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转化为LTextureData
   *
   * @param image
   * @return
   */
  private void create(LImage image) {
    if (image == null) {
      return;
    }
    int srcWidth = image.getWidth();
    int srcHeight = image.getHeight();

    this.hasAlpha = image.hasAlpha();

    if (GLEx.isPowerOfTwo(srcWidth) && GLEx.isPowerOfTwo(srcHeight)) {
      this.width = srcWidth;
      this.height = srcHeight;
      this.texHeight = srcHeight;
      this.texWidth = srcWidth;
      this.source = image.getByteBuffer();
      this.pixels = image.getPixels();

      if (image.isAutoDispose()) {
        image.dispose();
        image = null;
      }
      return;
    }

    int texWidth = GLEx.toPowerOfTwo(srcWidth);
    int texHeight = GLEx.toPowerOfTwo(srcHeight);

    this.width = srcWidth;
    this.height = srcHeight;
    this.texHeight = texHeight;
    this.texWidth = texWidth;

    LImage texImage = new LImage(texWidth, texHeight, hasAlpha);

    LGraphics g = texImage.getLGraphics();

    g.drawImage(image, 0, 0);

    if (this.height < texHeight - 1) {
      copyArea(texImage, g, 0, 0, width, 1, 0, texHeight - 1);
      copyArea(texImage, g, 0, height - 1, width, 1, 0, 1);
    }
    if (this.width < texWidth - 1) {
      copyArea(texImage, g, 0, 0, 1, height, texWidth - 1, 0);
      copyArea(texImage, g, width - 1, 0, 1, height, 1, 0);
    }

    this.source = texImage.getByteBuffer();
    this.pixels = texImage.getPixels();

    if (image.isAutoDispose()) {
      image.dispose();
      image = null;
    }
  }
 /**
  * 创建默认的选择器背景图片
  *
  * @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
 protected void setPixels() {
   int[] dest = image.getPixels();
   if (lastDispose > 0) {
     if (lastDispose == 3) {
       int n = frameCount - 2;
       if (n > 0) {
         lastImage = getFrame(n - 1);
       } else {
         lastImage = null;
       }
     }
     if (lastImage != null) {
       int[] prev = lastImage.getPixels();
       image.setPixels(prev, width, height);
       if (lastDispose == 2) {
         LGraphics g = image.getLGraphics();
         Color c = null;
         if (transparency) {
           c = new Color(0, 0, 0, 0);
         } else {
           c = new Color(lastBgColor);
         }
         g.setColor(c);
         g.fill(lastRect);
         g.dispose();
       }
     }
   }
   int pass = 1;
   int inc = 8;
   int iline = 0;
   for (int i = 0; i < ih; i++) {
     int line = i;
     if (interlace) {
       if (iline >= ih) {
         pass++;
         switch (pass) {
           case 2:
             iline = 4;
             break;
           case 3:
             iline = 2;
             inc = 4;
             break;
           case 4:
             iline = 1;
             inc = 2;
         }
       }
       line = iline;
       iline += inc;
     }
     line += iy;
     if (line < height) {
       int k = line * width;
       int dx = k + ix;
       int dlim = dx + iw;
       if ((k + width) < dlim) {
         dlim = k + width;
       }
       int sx = i * iw;
       while (dx < dlim) {
         int index = ((int) pixels[sx++]) & 0xff;
         int c = act[index];
         if (c != 0) {
           dest[dx] = c;
         }
         dx++;
       }
     }
   }
   image.setPixels(dest, width, height);
 }