Beispiel #1
0
 /**
  * Get the tile set that matches the given global tile id, only to be used when loading a map.
  *
  * @param gid a global tile id
  * @return the tileset containing the tile with the given global tile id, or <code>null</code>
  *     when no such tileset exists
  */
 public TileSet findTileSetForTileGID(int gid) {
   TileSet has = null;
   for (TileSet tileset : tilesets) {
     if (tileset.getFirstGid() <= gid) {
       has = tileset;
     }
   }
   return has;
 }
Beispiel #2
0
  /**
   * Returns the maximum tile height. This is the height of the highest tile in all tilesets or the
   * tile height used by this map if it's smaller.
   *
   * @return int The maximum tile height
   */
  public int getTileHeightMax() {
    int maxHeight = tileHeight;

    for (TileSet tileset : tilesets) {
      int height = tileset.getTileHeight();
      if (height > maxHeight) {
        maxHeight = height;
      }
    }

    return maxHeight;
  }
Beispiel #3
0
  /**
   * Removes a {@link TileSet} from the map, and removes any tiles in the set from the map layers. A
   * {@link MapChangedEvent} is fired when all processing is complete.
   *
   * @param tileset TileSet to remove
   * @throws LayerLockedException when the tileset is in use on a locked layer
   */
  public void removeTileset(TileSet tileset) throws LayerLockedException {
    // Sanity check
    final int tilesetIndex = tilesets.indexOf(tileset);
    if (tilesetIndex == -1) return;

    // Go through the map and remove any instances of the tiles in the set
    Iterator<Object> tileIterator = tileset.iterator();
    while (tileIterator.hasNext()) {
      Tile tile = (Tile) tileIterator.next();
      Iterator<MapLayer> layerIterator = getLayers();
      while (layerIterator.hasNext()) {
        MapLayer ml = (MapLayer) layerIterator.next();
        if (ml instanceof TileLayer) {
          ((TileLayer) ml).removeTile(tile);
        }
      }
    }

    tilesets.remove(tileset);
    fireTilesetRemoved(tilesetIndex);
  }
Beispiel #4
0
  /**
   * Adds a Tileset to this Map. If the set is already attached to this map, <code>addTileset</code>
   * simply returns.
   *
   * @param tileset a tileset to add
   */
  public void addTileset(TileSet tileset) {
    if (tileset == null || tilesets.indexOf(tileset) > -1) {
      return;
    }

    Tile t = tileset.getTile(0);

    if (t != null) {
      int tw = t.getWidth();
      int th = t.getHeight();
      if (tw != tileWidth) {
        if (tileWidth == 0) {
          tileWidth = tw;
          tileHeight = th;
        }
      }
    }

    tilesets.add(tileset);
    fireTilesetAdded(tileset);
  }