private void init (TiledMap map) { String axis = map.getProperties().get("staggeraxis", String.class); if (axis != null) { if (axis.equals("x")) { String index = map.getProperties().get("staggerindex", String.class); if (index != null) { if (index.equals("even")) { Integer length = map.getProperties().get("hexsidelength", Integer.class); if (length != null) { hexSideLength = length.intValue(); } else { if (staggerAxisX) { length = map.getProperties().get("tilewidth", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue(); length = map.getProperties().get("tileheight", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue();
private void init (TiledMap map) { String axis = map.getProperties().get("staggeraxis", String.class); if (axis != null) { if (axis.equals("x")) { String index = map.getProperties().get("staggerindex", String.class); if (index != null) { if (index.equals("even")) { Integer length = map.getProperties().get("hexsidelength", Integer.class); if (length != null) { hexSideLength = length.intValue(); } else { if (staggerAxisX) { length = map.getProperties().get("tilewidth", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue(); length = map.getProperties().get("tileheight", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue();
private void stripUnusedTiles () { int mapWidth = map.getProperties().get("width", Integer.class); int mapHeight = map.getProperties().get("height", Integer.class); int numlayers = map.getLayers().getCount(); int bucketSize = mapWidth * mapHeight * numlayers; Iterator<MapLayer> it = map.getLayers().iterator(); while (it.hasNext()) { MapLayer layer = it.next(); // some layers can be plain MapLayer instances (ie. object groups), just ignore them if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tlayer = (TiledMapTileLayer)layer; for (int y = 0; y < mapHeight; ++y) { for (int x = 0; x < mapWidth; ++x) { if (tlayer.getCell(x, y) != null) { TiledMapTile tile = tlayer.getCell(x, y).getTile(); if (tile instanceof AnimatedTiledMapTile) { AnimatedTiledMapTile aTile = (AnimatedTiledMapTile)tile; for (StaticTiledMapTile t : aTile.getFrameTiles()) { addTile(t, bucketSize); } } // Adds non-animated tiles and the base animated tile addTile(tile, bucketSize); } } } } } }
private void stripUnusedTiles () { int mapWidth = map.getProperties().get("width", Integer.class); int mapHeight = map.getProperties().get("height", Integer.class); int numlayers = map.getLayers().getCount(); int bucketSize = mapWidth * mapHeight * numlayers; Iterator<MapLayer> it = map.getLayers().iterator(); while (it.hasNext()) { MapLayer layer = it.next(); // some layers can be plain MapLayer instances (ie. object groups), just ignore them if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tlayer = (TiledMapTileLayer)layer; for (int y = 0; y < mapHeight; ++y) { for (int x = 0; x < mapWidth; ++x) { if (tlayer.getCell(x, y) != null) { TiledMapTile tile = tlayer.getCell(x, y).getTile(); if (tile instanceof AnimatedTiledMapTile) { AnimatedTiledMapTile aTile = (AnimatedTiledMapTile)tile; for (StaticTiledMapTile t : aTile.getFrameTiles()) { addTile(t, bucketSize); } } // Adds non-animated tiles and the base animated tile addTile(tile, bucketSize); } } } } } }
renderer = new IsometricTiledMapRenderer(map, 1f / 64f); String mapCustomValue = map.getProperties().get(MAP_PROPERTY_NAME, String.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + MAP_PROPERTY_NAME + ", Value : " + mapCustomValue); if (!MAP_PROPERTY_VALUE.equals(mapCustomValue)) { boolean boolCustomValue = map.getProperties().get(BOOL_PROPERTY_NAME, Boolean.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + BOOL_PROPERTY_NAME + ", Value : " + boolCustomValue); if (boolCustomValue != BOOL_PROPERTY_VALUE) { int intCustomValue = map.getProperties().get(INT_PROPERTY_NAME, Integer.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + INT_PROPERTY_NAME + ", Value : " + intCustomValue); if (intCustomValue != INT_PROPERTY_VALUE) { float floatCustomValue = map.getProperties().get(FLOAT_PROPERTY_NAME, Float.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + FLOAT_PROPERTY_NAME + ", Value : " + floatCustomValue); if (floatCustomValue != FLOAT_PROPERTY_VALUE) {
String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); String elementName = element.getName(); if (elementName.equals("properties")) { loadProperties(map.getProperties(), element); } else if (elementName.equals("tileset")) { loadTileset(map, element, tmxFile, resolver);
String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); String elementName = element.getName(); if (elementName.equals("properties")) { loadProperties(map.getProperties(), element); } else if (elementName.equals("tileset")) { loadTileset(map, element, tmxFile, resolver);
int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = map.getProperties().get("tilewidth", Integer.class); int tileHeight = map.getProperties().get("tileheight", Integer.class); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = map.getProperties().get("tilewidth", Integer.class); int tileHeight = map.getProperties().get("tileheight", Integer.class); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
/** Loads the map data, given the XML root element and an {@link ImageResolver} used to return the tileset Textures * @param root the XML root element * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} * @return the {@link TiledMap} */ private TiledMap loadMap (Element root, FileHandle tmxFile, ImageResolver imageResolver) { TiledMap map = new TiledMap(); Element properties = root.getChildByName("Properties"); if (properties != null) { loadProperties(map.getProperties(), properties); } Element tilesheets = root.getChildByName("TileSheets"); for (Element tilesheet : tilesheets.getChildrenByName("TileSheet")) { loadTileSheet(map, tilesheet, tmxFile, imageResolver); } Element layers = root.getChildByName("Layers"); for (Element layer : layers.getChildrenByName("Layer")) { loadLayer(map, layer); } return map; }
/** Loads the map data, given the XML root element and an {@link ImageResolver} used to return the tileset Textures * @param root the XML root element * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} * @return the {@link TiledMap} */ private TiledMap loadMap (Element root, FileHandle tmxFile, ImageResolver imageResolver) { TiledMap map = new TiledMap(); Element properties = root.getChildByName("Properties"); if (properties != null) { loadProperties(map.getProperties(), properties); } Element tilesheets = root.getChildByName("TileSheets"); for (Element tilesheet : tilesheets.getChildrenByName("TileSheet")) { loadTileSheet(map, tilesheet, tmxFile, imageResolver); } Element layers = root.getChildByName("Layers"); for (Element layer : layers.getChildrenByName("Layer")) { loadLayer(map, layer); } return map; }
String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); loadProperties(map.getProperties(), properties);
String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); loadProperties(map.getProperties(), properties);
batch = new SpriteBatch(); map = new TmxMapLoader().load("data/maps/tiled-objects/test-load-mapobjects.tmx"); MapProperties properties = map.getProperties(); shapeRenderer = new ShapeRenderer();
String atlasFilePath = map.getProperties().get("atlas", String.class); if (atlasFilePath == null) { FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
String atlasFilePath = map.getProperties().get("atlas", String.class); if (atlasFilePath == null) { FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
@Override protected void initialize() { map = new TmxMapLoader().load(mapFilename); layers = map.getLayers().getByType(TiledMapTileLayer.class); width = map.getProperties().get("width", Integer.class); height = map.getProperties().get("height", Integer.class); tileWidth = map.getProperties().get("tilewidth", Integer.class); tileHeight = map.getProperties().get("tileheight", Integer.class); }
@Override protected void initialize() { map = new TmxMapLoader().load(mapFilename); layers = map.getLayers().getByType(TiledMapTileLayer.class); width = map.getProperties().get("width", Integer.class); height = map.getProperties().get("height", Integer.class); tileWidth = map.getProperties().get("tilewidth", Integer.class); tileHeight = map.getProperties().get("tileheight", Integer.class); }
@Override protected void initialize() { map = new TmxMapLoader().load(mapFilename); layers = map.getLayers().getByType(TiledMapTileLayer.class); width = map.getProperties().get("width", Integer.class); height = map.getProperties().get("height", Integer.class); tileWidth = map.getProperties().get("tilewidth", Integer.class); tileHeight = map.getProperties().get("tileheight", Integer.class); }
@Override protected void setup(int e, Terrain terrain, TerrainAsset asset) { if (terrain.id == null ) { throw new RuntimeException("TerrainManager: terrain.id is null."); } asset.map = loader.load(terrain.id); asset.renderer = new OrthogonalTiledMapRenderer(asset.map); //asset.layers = map.getLayers().getByType(TiledMapTileLayer.class); final MapProperties properties = asset.map.getProperties(); asset.width = properties.get("width", Integer.class); asset.height = properties.get("height", Integer.class); asset.tileWidth = properties.get("tilewidth", Integer.class); asset.tileHeight = properties.get("tileheight", Integer.class); // set unitialized size to asset. if (!mSize.has(e)) { mSize.create(e).set(asset.pixelWidth(), asset.pixelHeight()); } } }