Exemple #1
0
 public void setField2DBackground(Field2D field, HashMap pathMap, String fileName) {
   setField2D(field);
   LImage background = null;
   if (fileName != null) {
     setTileBackground(fileName);
     background = getBackground();
   } else {
     background = LImage.createImage(getWidth(), getHeight(), false);
   }
   LGraphics g = background.getLGraphics();
   for (int i = 0; i < field.getWidth(); i++) {
     for (int j = 0; j < field.getHeight(); j++) {
       int index = field.getType(j, i);
       Object o = pathMap.get(new Integer(index));
       if (o != null) {
         if (o instanceof LImage) {
           g.drawImage(
               ((LImage) o).getBufferedImage(),
               field.tilesToWidthPixels(i),
               field.tilesToHeightPixels(j),
               null);
         } else if (o instanceof Actor) {
           addObject(((Actor) o), field.tilesToWidthPixels(i), field.tilesToHeightPixels(j));
         }
       }
     }
   }
   g.dispose();
   setBackground(background);
 }
Exemple #2
0
 /**
  * 返回指定资源文件中的指定资源为LImage
  *
  * @param fileName
  * @param resName
  * @return
  */
 public static LImage openLImage(String fileName, String resName) {
   byte[] buffer = null;
   try {
     buffer = LPKResource.openResource(fileName, resName);
     return LImage.createImage(buffer);
   } catch (Exception e) {
     throw new RuntimeException("File not found. ( " + resName + " )");
   }
 }
 /**
  * 创建默认的选择器背景图片
  *
  * @param w
  * @param h
  * @return
  */
 private LImage createDefaultDialog(int w, int h) {
   if (lazyDialog == null) {
     lazyDialog = new HashMap<String, LImage>(10);
   }
   int hash = 1;
   hash = LSystem.unite(hash, w);
   hash = LSystem.unite(hash, h);
   String key = String.valueOf(hash);
   LImage o = (LImage) lazyDialog.get(key);
   if (o == null) {
     o = LImage.createImage(w, h, true);
     LGraphics g = o.getLGraphics();
     LGradation.getInstance(Color.white, Color.black, w, h).drawHeight(g, 0, 0);
     g.setColor(Color.black);
     g.drawRect(0, 0, w - 1, h - 1);
     g.dispose();
     lazyDialog.put(key, o);
   }
   return o;
 }
Exemple #4
0
  public void setTileBackground(LImage image) {
    if (image == null) {
      return;
    }

    int layerWidth = getWidth();
    int layerHeight = getHeight();
    int tileWidth = image.getWidth();
    int tileHeight = image.getHeight();

    LImage background = LImage.createImage(layerWidth, layerHeight, false);
    LGraphics g = background.getLGraphics();
    for (int x = 0; x < layerWidth; x += tileWidth) {
      for (int y = 0; y < layerHeight; y += tileHeight) {
        g.drawImage(image, x, y);
      }
    }
    g.dispose();

    setBackground(background);
  }
Exemple #5
0
 public void setTileBackground(String fileName) {
   setTileBackground(LImage.createImage(fileName));
 }