Examples of DrawableTile


Examples of net.sourceforge.dsnk.gui.map.model.DrawableTile

   * @throws IOException
   *             if textures for drawable tile cannot be read.
   */
  private DrawableTile convertToDrawableTile(MapCell mapCell)
      throws IOException {
    DrawableTile drawableTile = new DrawableTile();

    int index = mapCell.getIndex();
    // a tile group consists of 32 tile objects
    // to get tile group index divide by 32
    // to get tile object index in tile group get
    // the modulo of 32
    int tileGroupIdx = index / 32;
    int tileIdx = index % 32;

    // fetch the land tile
    LandTile tile = this.tileGroups[tileGroupIdx].getTiles()[tileIdx];
    TexIdx textureIndex = this.texIdxs[(int) tile.getTextureId()];

    // fetch the texture object
    Texture texture = null;
    try {
      texture = this.textureCache.get(textureIndex.getStart());
    } catch (CacheItemNotFoundException e) {
      // not found in cache, so load
      texture = textureReader.read(textureIndex);
      // put texture into cache
      this.textureCache.put(textureIndex.getStart(), texture);
    }

    // and the image of the texture
    Image textureImg = null;
    if (texture != null) {
      textureImg = texture.getImage();
    } else {
      // create dummy image
      textureImg = graphicsConfiguration.createCompatibleImage(64, 64,
          Transparency.TRANSLUCENT);
      Graphics g = textureImg.getGraphics();
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, 64, 64);
      g.setColor(Color.WHITE);
      g.drawString("N/A", 22, 35);
    }

    // create bounds object (note: x and y is not set here)
    Rectangle bounds = new Rectangle(0, 0, 64, 64);

    // set drawable tile properties
    drawableTile.setAltitude(mapCell.getAltitude());
    drawableTile.setFlags(tile.getFlags());
    drawableTile.setName(tile.getName());
    drawableTile.setTexture(textureImg);
    drawableTile.setRelativeBounds(bounds);

    return drawableTile;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.