Пример #1
0
  /**
   * Load all tiles from the layer
   *
   * @param element the layer element
   * @return an array containing all tile information of this layer
   * @throws IOException
   * @throws Exception
   */
  private TileInfo[][] loadTiles(TmxLayer element) throws IOException, Exception {
    List<Integer> ids = element.getData().getIds();
    int id = 0;

    TileInfo[][] result = new TileInfo[width][height];
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        int tileId = ids.get(id++);
        if (tileId == 0) {
          result[x][y] = null;
        } else {
          TileSet set = map.findTileSet(tileId);

          if (set != null) {
            result[x][y] =
                new TileInfo(
                    set.getIndex(),
                    tileId - set.getFirstGID(),
                    tileId,
                    set.getTileProperties(tileId));
          } else {
            result[x][y] = new TileInfo(0, 0, tileId, null);
          }
        }
      }
    }

    return result;
  }