Exemplo n.º 1
0
  /**
   * 渲染当前层画面到LGraphics之上
   *
   * @param g
   * @param x
   * @param y
   * @param sx
   * @param sy
   * @param width
   * @param ty
   * @param isLine
   * @param mapTileWidth
   * @param mapTileHeight
   */
  public void draw(
      LGraphics g,
      int x,
      int y,
      int sx,
      int sy,
      int width,
      int ty,
      boolean isLine,
      int mapTileWidth,
      int mapTileHeight) {

    int tileCount = map.getTileSetCount();

    int nx, ny, sheetX, sheetY, tileOffsetY;

    for (int tileset = 0; tileset < tileCount; tileset++) {

      TMXTileSet set = null;

      for (int tx = 0; tx < width; tx++) {

        nx = sx + tx;
        ny = sy + ty;

        if ((nx < 0) || (ny < 0)) {
          continue;
        }
        if ((nx >= this.width) || (ny >= this.height)) {
          continue;
        }

        if (data[nx][ny][0] == tileset) {
          if (set == null) {
            set = map.getTileSet(tileset);
          }

          sheetX = set.getTileX(data[nx][ny][1]);
          sheetY = set.getTileY(data[nx][ny][1]);

          tileOffsetY = set.tileHeight - mapTileHeight;

          set.tiles.draw(
              g, x + (tx * mapTileWidth), y + (ty * mapTileHeight) - tileOffsetY, sheetX, sheetY);
        }
      }

      if (isLine) {
        if (set != null) {
          set = null;
        }
        map.rendered(ty, ty + sy, index);
      }
    }
  }
Exemplo n.º 2
0
  public LTexture getTileImage(int x, int y, int layerIndex) {
    TMXLayer layer = (TMXLayer) layers.get(layerIndex);

    int tileSetIndex = layer.data[x][y][0];
    if ((tileSetIndex >= 0) && (tileSetIndex < tileSets.size())) {
      TMXTileSet tileSet = (TMXTileSet) tileSets.get(tileSetIndex);

      int sheetX = tileSet.getTileX(layer.data[x][y][1]);
      int sheetY = tileSet.getTileY(layer.data[x][y][1]);

      return tileSet.tiles.getSubImage(sheetX, sheetY);
    }

    return null;
  }