int firstgid = 1; for (TiledMapTileSet tileset : tilesets) { firstgid += tileset.size(); TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(id); tileset.getProperties().put("firstgid", firstgid); int gid = firstgid; TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY)); tile.setId(gid); tileset.putTile(gid++, tile); loadProperties(tileset.getProperties(), properties);
/** @param id id of the {@link TiledMapTile} to get. * @return tile with matching id, null if it doesn't exist */ public TiledMapTile getTile (int id) { // The purpose of backward iteration here is to maintain backwards compatibility // with maps created with earlier versions of a shared tileset. The assumption // is that the tilesets are in order of ascending firstgid, and by backward // iterating precedence for conflicts is given to later tilesets in the list, // which are likely to be the earlier version of any given gid. // See TiledMapModifiedExternalTilesetTest for example of this issue. for (int i = tilesets.size-1; i >= 0; i--) { TiledMapTileSet tileset = tilesets.get(i); TiledMapTile tile = tileset.getTile(id); if (tile != null) { return tile; } } return null; }
private String tilesetNameFromTileId (TiledMap map, int tileid) { String name = ""; if (tileid == 0) { return ""; } for (TiledMapTileSet tileset : map.getTileSets()) { int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class); if (firstgid == -1) continue; // skip this tileset if (tileid >= firstgid) { name = tileset.getName(); } else { return name; } } return name; }
TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(id++, tile); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tile.getId(), tile); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); IntArray intervals = new IntArray(); for (Element frameElement: animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); tileset.putTile(tile.getId(), tile);
if (name.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (name.equals("Null")) { x += currentChild.getIntAttribute("Count"); } else if (name.equals("Static")) { Cell cell = new Cell(); cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index"))); layer.setCell(x++, y, cell); } else if (name.equals("Animated")) { if (frameName.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (frameName.equals("Static")) { frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
/** @param name Name of the {@link TiledMapTileSet} to retrieve. * @return tileset with matching name, null if it doesn't exist */ public TiledMapTileSet getTileSet (String name) { for (TiledMapTileSet tileset : tilesets) { if (name.equals(tileset.getName())) { return tileset; } } return null; }
TiledMapTileSet tileset = new TiledMapTileSet(); MapProperties props = tileset.getProperties(); tileset.setName(name); props.put("firstgid", firstgid); props.put("imagesource", imageSource); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tileid, tile); TiledMapTile tile = tileset.getTile(tileid); if (tile == null) { Element imageElement = tileElement.getChildByName("image"); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tileid, tile); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); IntArray intervals = new IntArray(); for (Element frameElement: animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); tileset.putTile(tile.getId(), tile);
if (name.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (name.equals("Null")) { x += currentChild.getIntAttribute("Count"); } else if (name.equals("Static")) { Cell cell = new Cell(); cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index"))); layer.setCell(x++, y, cell); } else if (name.equals("Animated")) { if (frameName.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (frameName.equals("Static")) { frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
/** @param name Name of the {@link TiledMapTileSet} to retrieve. * @return tileset with matching name, null if it doesn't exist */ public TiledMapTileSet getTileSet (String name) { for (TiledMapTileSet tileset : tilesets) { if (name.equals(tileset.getName())) { return tileset; } } return null; }
TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(id++, tile); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tile.getId(), tile); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); IntArray intervals = new IntArray(); for (Element frameElement: animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); tileset.putTile(tile.getId(), tile);
int firstgid = 1; for (TiledMapTileSet tileset : tilesets) { firstgid += tileset.size(); TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(id); tileset.getProperties().put("firstgid", firstgid); int gid = firstgid; TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY)); tile.setId(gid); tileset.putTile(gid++, tile); loadProperties(tileset.getProperties(), properties);
private String tilesetNameFromTileId (TiledMap map, int tileid) { String name = ""; if (tileid == 0) { return ""; } for (TiledMapTileSet tileset : map.getTileSets()) { int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class); if (firstgid == -1) continue; // skip this tileset if (tileid >= firstgid) { name = tileset.getName(); } else { return name; } } return name; }
String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class); if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) { throw new RuntimeException("Failed to get tileset properties"); TiledMapTile tile = tileset.getTile(1); String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class); if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) {
/** @param id id of the {@link TiledMapTile} to get. * @return tile with matching id, null if it doesn't exist */ public TiledMapTile getTile (int id) { // The purpose of backward iteration here is to maintain backwards compatibility // with maps created with earlier versions of a shared tileset. The assumption // is that the tilesets are in order of ascending firstgid, and by backward // iterating precedence for conflicts is given to later tilesets in the list, // which are likely to be the earlier version of any given gid. // See TiledMapModifiedExternalTilesetTest for example of this issue. for (int i = tilesets.size-1; i >= 0; i--) { TiledMapTileSet tileset = tilesets.get(i); TiledMapTile tile = tileset.getTile(id); if (tile != null) { return tile; } } return null; }
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
private void processSingleMap (File mapFile, FileHandle dirHandle, Settings texturePackerSettings) throws IOException { boolean combineTilesets = this.settings.combineTilesets; if (combineTilesets == false) { tilesetUsedIds = new HashMap<String, IntArray>(); tilesetsToPack = new ObjectMap<String, TiledMapTileSet>(); } map = mapLoader.load(mapFile.getCanonicalPath()); // if enabled, build a list of used tileids for the tileset used by this map boolean stripUnusedTiles = this.settings.stripUnusedTiles; if (stripUnusedTiles) { stripUnusedTiles(); } else { for (TiledMapTileSet tileset : map.getTileSets()) { String tilesetName = tileset.getName(); if (!tilesetsToPack.containsKey(tilesetName)) { tilesetsToPack.put(tilesetName, tileset); } } } if (combineTilesets == false) { FileHandle tmpHandle = new FileHandle(mapFile.getName()); this.settings.atlasOutputName = tmpHandle.nameWithoutExtension(); packTilesets(dirHandle, texturePackerSettings); } FileHandle tmxFile = new FileHandle(mapFile.getCanonicalPath()); writeUpdatedTMX(map, tmxFile); }
TiledMapTileSet tileset = new TiledMapTileSet(); MapProperties props = tileset.getProperties(); tileset.setName(name); props.put("firstgid", firstgid); props.put("imagesource", imageSource); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tileid, tile); TiledMapTile tile = tileset.getTile(tileid); if (tile == null) { Element imageElement = tileElement.getChildByName("image"); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tileid, tile); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); IntArray intervals = new IntArray(); for (Element frameElement: animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); tileset.putTile(tile.getId(), tile);
int firstgid = 1; for (TiledMapTileSet tileset : tilesets) { firstgid += tileset.size(); TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(id); tileset.getProperties().put("firstgid", firstgid); int gid = firstgid; TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY)); tile.setId(gid); tileset.putTile(gid++, tile); loadProperties(tileset.getProperties(), properties);