@Override protected void initialize() { super.initialize(); cableMask = mapSystem.getMask("cable-type"); for (TiledMapTileSet tileSet : mapSystem.map.getTileSets()) { for (TiledMapTile tile : tileSet) { MapProperties properties = tile.getProperties(); if (properties.containsKey("cable-type")) { if ((Boolean) properties.get("cable-state")) { tilesOn.put((Integer) properties.get("cable-type"), tile); } else { tilesOff.put((Integer) properties.get("cable-type"), tile); } } } } }
/** Returns the tileset name associated with the specified tile id * @return a tileset name */ 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; }
private void findTileFrames() { for (TiledMapTileSet tileSet : tiledMap.getTileSets()) { for (TiledMapTile tile : tileSet) { final MapProperties tileProperties = tile.getProperties(); if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID) && tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) { tileFrames.put(tileProperties.get(JRPG_TILE_ANIMATION_INDEX, Integer.class), tile); } } } }
/** * Create a new Goban * * @param screen Screen where this Goban lives. * @param map The map to load for this Goban */ public Goban(GoGameScreen screen, TiledMap map) { this.screen = screen; this.map = screen.getMap(); gobanOriginCoords = new Vector2(Float.parseFloat(map.getProperties().get("goOriginX", String.class)), Float.parseFloat(map.getProperties().get("goOriginY", String.class))); final TiledMapTileSet stoneTS = map.getTileSets().getTileSet("stoneTS"); int firstGid = stoneTS.getProperties().get("firstgid", Integer.class); this.blackStone = stoneTS.getTile(firstGid); this.whiteStone = stoneTS.getTile(firstGid + 1); this.gobanSize = Integer.parseInt(map.getProperties().get("gobanSize", String.class)); engineThread = generateGameThread(); }
/** * Loads the map and sets up its display parameters */ private void setupMap() { manager.load("com/ragego/gui/maps/" + getMapToLoad() + ".tmx", TiledMap.class); manager.finishLoading(); Gdx.app.log(getClass().getCanonicalName(), "Map loaded"); map = manager.get("com/ragego/gui/maps/" + getMapToLoad() + ".tmx"); renderer = new IsometricTiledMapRenderer(map); worldCamera = new OrthographicCamera(); gridLayer = (TiledMapTileLayer) map.getLayers().get("grid"); selection = (TiledMapTileLayer) map.getLayers().get("selection"); final TiledMapTileSet toolTS = map.getTileSets().getTileSet("toolTS"); selectionTile = toolTS.getTile(toolTS.getProperties().get("firstgid", Integer.class)); backgroundColor = new Color(GuiUtils.colorFromHexString(map.getProperties().get("backgroundcolor", String.class))); }
/** 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; }
public static TiledMapTile getTile(final TiledMap tiledMap, final String tilesetName, final int tileId) { final TiledMapTileSet tileset = tiledMap.getTileSets().getTileSet(tilesetName); return (tileset != null) ? tileset.getTile(tileset.getProperties().get(FISRTGID_PARAM, Integer.class) + tileId) : null; }
public TiledMapTileSet getTileSet(String name) { return tiledMap.getTileSets().getTileSet(name); }
/** Traverse the specified tilesets, optionally lookup the used ids and pass every tile image to the {@link TexturePacker}, * optionally ignoring unused tile ids */ private void packTilesets (ObjectMap<String, TiledMapTileSet> sets, FileHandle inputDirHandle, File outputDir, Settings texturePackerSettings) throws IOException { BufferedImage tile; Vector2 tileLocation; TileSetLayout packerTileSet; Graphics g; packer = new TexturePacker(texturePackerSettings); for (TiledMapTileSet set : sets.values()) { String tilesetName = set.getName(); System.out.println("Processing tileset " + tilesetName); IntArray usedIds = this.settings.stripUnusedTiles ? getUsedIdsBucket(tilesetName, -1) : null; int tileWidth = set.getProperties().get("tilewidth", Integer.class); int tileHeight = set.getProperties().get("tileheight", Integer.class); int firstgid = set.getProperties().get("firstgid", Integer.class); String imageName = set.getProperties().get("imagesource", String.class); TileSetLayout layout = new TileSetLayout(firstgid, set, inputDirHandle); for (int gid = layout.firstgid, i = 0; i < layout.numTiles; gid++, i++) { if (usedIds != null && !usedIds.contains(gid)) { System.out.println("Stripped id #" + gid + " from tileset \"" + tilesetName + "\""); continue; } tileLocation = layout.getLocation(gid); tile = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_4BYTE_ABGR); g = tile.createGraphics(); g.drawImage(layout.image, 0, 0, tileWidth, tileHeight, (int)tileLocation.x, (int)tileLocation.y, (int)tileLocation.x + tileWidth, (int)tileLocation.y + tileHeight, null); if (isBlended(tile)) setBlended(gid); System.out.println("Adding " + tileWidth + "x" + tileHeight + " (" + (int)tileLocation.x + ", " + (int)tileLocation.y + ")"); packer.addImage(tile, this.settings.atlasOutputName + "_" + (gid-1)); } } File outputDirTilesets = getRelativeFile(outputDir, this.settings.tilesetOutputDirectory); outputDirTilesets.mkdirs(); packer.pack(outputDirTilesets, this.settings.atlasOutputName + ".atlas"); }