public void LoadTilesWithoutBody(TiledMap tileMap, World world) { TiledMapTileLayer layer = (TiledMapTileLayer) tileMap.getLayers().get("Empty"); float tileSize = layer.getTileHeight(); for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { Cell cell = layer.getCell(col, row); if (cell == null || cell.getTile() == null) continue; // create float x = col * tileSize / B2D.PPM; float y = row * tileSize / B2D.PPM; int tileType = cell.getTile().getId(); tileType--; if (tileType == 15) { GameStats.GameSpawnPosition = new Vector2(x, y); Cell c = new Cell(); layer.setCell(col, row, c); } if (tileType <= 14) { // e element normal int id = tileType; GameTileRenderer.tlz[col][row] = id; } } } }
private boolean isCellBlocked(float x, float y) { Vector2 newCoords = UtilityMethods.screenToMapCoordinate(new Vector2(x, y)); // System.out.println("Player: x" + sprite.getX() + " y " + sprite.getY()); // System.out.println("Tile: x" + newCoords.x + " y " + newCoords.y); // sprite.setPosition(newCoords.x, newCoords.y); Cell cell = collisionLayer.getCell( (int) (newCoords.x / collisionLayer.getTileWidth()), (int) (newCoords.y / collisionLayer.getTileHeight())); // System.out.println(cell); return cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey("blocked"); }
public boolean isTileCollidable(int column, int row) { // System.out.println(column + "," + row + " testing"); Cell tileCell = metaLayer.getCell(column, row); if (tileCell != null) { TiledMapTile tile = tileCell.getTile(); MapProperties properties = tile.getProperties(); if (properties.containsKey("collidable")) { Object value = properties.get("collidable"); if (value.toString().compareTo("1") == 0) { return true; } } } return false; }
private void _loadSpecialTilesRoutine(TiledMap map) { // System.out.println("_loadSpecialTilesRoutine"); Iterator<TiledMapTile> tiles = map.getTileSets().getTileSet(0).iterator(); // System.out.println(map.getTileSets().getTileSet(0).size()); while (tiles.hasNext()) { TiledMapTile tile = tiles.next(); if (tile.getProperties().containsKey("debug")) { // System.out.println("debug tile found!!"); debugCell = new Cell(); debugCell.setTile(tile); } else if (tile.getProperties().containsKey("collidable")) { // System.out.println("collidable tile found!!"); collidableCell = new Cell(); collidableCell.setTile(tile); } } }
private void initCollidableBlocks() { layer = (TiledMapTileLayer) map.getLayers().get("Collidable"); for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { Cell cell = layer.getCell(col, row); // Checamos para ver se existe algum tile aqui if (cell == null || cell.getTile() == null) { collidableArea[col][row] = false; continue; } // adicionamos essa posição à collidableBlocks; collidableArea[col][row] = true; } } }
private void generatePlatforms(String LayerName) { TiledMapTileLayer layer = (TiledMapTileLayer) tileMap.getLayers().get(LayerName); tileSize = layer.getTileHeight(); BodyDef bdef = new BodyDef(); FixtureDef fdef = new FixtureDef(); // iterate over tiles and build box2d objects and chaining them together for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { Cell cell = layer.getCell(col, row); if (cell == null) continue; if (cell.getTile() == null) continue; bdef.type = BodyType.StaticBody; bdef.position.set((col + 0.5f) * tileSize / PPM, (row + 0.5f) * tileSize / PPM); ChainShape cs = new ChainShape(); Vector2[] v = new Vector2[3]; v[0] = new Vector2(-tileSize / 2 / PPM, -tileSize / 2 / PPM); v[1] = new Vector2(-tileSize / 2 / PPM, +tileSize / 2 / PPM); v[2] = new Vector2(+tileSize / 2 / PPM, +tileSize / 2 / PPM); cs.createChain(v); fdef.friction = 0; fdef.shape = cs; fdef.filter.categoryBits = B2DVars.BIT_BLOCKS; fdef.filter.maskBits = B2DVars.BIT_PLAYER; fdef.isSensor = false; world.createBody(bdef).createFixture(fdef); } } }
protected Cell createTileLayerCell( boolean flipHorizontally, boolean flipVertically, boolean flipDiagonally) { Cell cell = new Cell(); if (flipDiagonally) { if (flipHorizontally && flipVertically) { cell.setFlipHorizontally(true); cell.setRotation(yUp ? Cell.ROTATE_270 : Cell.ROTATE_90); } else if (flipHorizontally) { cell.setRotation(yUp ? Cell.ROTATE_270 : Cell.ROTATE_90); } else if (flipVertically) { cell.setRotation(yUp ? Cell.ROTATE_90 : Cell.ROTATE_270); } else { cell.setFlipVertically(true); cell.setRotation(yUp ? Cell.ROTATE_270 : Cell.ROTATE_90); } } else { cell.setFlipHorizontally(flipHorizontally); cell.setFlipVertically(flipVertically); } return cell; }
public void LoadTilesWithBody(TiledMap tileMap, World world) { TiledMapTileLayer layer = (TiledMapTileLayer) tileMap.getLayers().get("Body"); BodyDef def = new BodyDef(); FixtureDef fdef = new FixtureDef(); def.type = BodyType.StaticBody; FixtureDef sensorDef = new FixtureDef(); sensorDef.isSensor = true; int coinID = 0; int starID = 0; float tileSize = layer.getTileHeight(); GameTileRenderer.width = layer.getWidth(); GameTileRenderer.height = layer.getHeight(); GameTileRenderer.tlz = new int[GameTileRenderer.width][GameTileRenderer.height]; for (int[] row : GameTileRenderer.tlz) Arrays.fill(row, -1); for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { Cell cell = layer.getCell(col, row); if (cell == null || cell.getTile() == null) continue; // create def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); float x = col * tileSize / B2D.PPM; float y = row * tileSize / B2D.PPM; int tileType = cell.getTile().getId(); tileType--; if (tileType <= 14) { // e element normal int id = tileType; GameTileRenderer.tlz[col][row] = id; ChainShape shape = new ChainShape(); Vector2[] v = new Vector2[5]; if (tileType < 14) { v[0] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[1] = new Vector2(-tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[2] = new Vector2(tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[3] = new Vector2(tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[4] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); } else { v[0] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[1] = new Vector2(-tileSize / 2 / B2D.PPM, 0 / B2D.PPM); v[2] = new Vector2(tileSize / 2 / B2D.PPM, 0 / B2D.PPM); v[3] = new Vector2(tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[4] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); } shape.createChain(v); fdef.friction = 0; fdef.shape = shape; if (tileType < 14) world.createBody(def).createFixture(fdef).setUserData("tile"); else world.createBody(def).createFixture(fdef).setUserData("die"); } if (tileType == 16) { // coin Cell c = new Cell(); layer.setCell(col, row, c); if (GameStats.AddTheCoin(coinID)) { GameWorld.cr.coins.add(new Vector2(x, y)); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); ChainShape shape = new ChainShape(); Vector2[] v = new Vector2[5]; v[0] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[1] = new Vector2(-tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[2] = new Vector2(tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[3] = new Vector2(tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[4] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); shape.createChain(v); sensorDef.shape = shape; TileData tmp = new TileData(coinID, "coin"); coinID++; world.createBody(def).createFixture(sensorDef).setUserData(tmp); } else { GameWorld.cr.coins.add(null); coinID++; } } if (tileType == 17) { Cell c = new Cell(); layer.setCell(col, row, c); GameWorld.cr.stars.add(new Vector2(x, y)); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); ChainShape shape = new ChainShape(); Vector2[] v = new Vector2[5]; v[0] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[1] = new Vector2(-tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[2] = new Vector2(tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[3] = new Vector2(tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[4] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); shape.createChain(v); sensorDef.shape = shape; TileData tmp = new TileData(starID, "star"); starID++; world.createBody(def).createFixture(sensorDef).setUserData(tmp); } if (tileType == 18) { Cell c = new Cell(); layer.setCell(col, row, c); GameMap.flagposition = new Vector2(x, y); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); ChainShape shape = new ChainShape(); Vector2[] v = new Vector2[5]; v[0] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[1] = new Vector2(-tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[2] = new Vector2(tileSize / 2 / B2D.PPM, tileSize / 2 / B2D.PPM); v[3] = new Vector2(tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); v[4] = new Vector2(-tileSize / 2 / B2D.PPM, -tileSize / 2 / B2D.PPM); shape.createChain(v); sensorDef.shape = shape; world.createBody(def).createFixture(sensorDef).setUserData("finish"); } // tiles.add(new Vector2(x, y)); } } }
public void LoadGameTiles(TiledMap tileMap, World world) { TiledMapTileLayer layer = (TiledMapTileLayer) tileMap.getLayers().get("Tiles"); BodyDef def = new BodyDef(); FixtureDef fdef = new FixtureDef(); def.type = BodyType.StaticBody; FixtureDef sensorDef = new FixtureDef(); sensorDef.isSensor = true; int coinID = 0; int starID = 0; float tileSize = layer.getTileHeight(); GameTileRenderer.width = layer.getWidth(); GameTileRenderer.height = layer.getHeight(); GameTileRenderer.tlz = new int[GameTileRenderer.width][GameTileRenderer.height]; for (int[] row : GameTileRenderer.tlz) Arrays.fill(row, -1); for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { Cell cell = layer.getCell(col, row); if (cell == null || cell.getTile() == null) continue; // create def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); float x = col * tileSize / B2D.PPM; float y = row * tileSize / B2D.PPM; int tileType = cell.getTile().getId(); tileType--; if (tileType == 11) { GameStats.GameSpawnPosition = new Vector2(x, y); Cell c = new Cell(); layer.setCell(col, row, c); } if (tileType == 12) { Cell c = new Cell(); layer.setCell(col, row, c); GameMap.flagposition = new Vector2(x, y); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); sensorDef.shape = createShape(tileSize); world.createBody(def).createFixture(sensorDef).setUserData("finish"); } if (tileType == 8) { // e spike int id = tileType; GameTileRenderer.tlz[col][row] = id; fdef.friction = 0; fdef.shape = createSpikeShape(tileSize); world.createBody(def).createFixture(fdef).setUserData("die"); } if (tileType == 0 || tileType == 4) { // e element normal int id = tileType; GameTileRenderer.tlz[col][row] = id; fdef.friction = 0; fdef.shape = createShape(tileSize); world.createBody(def).createFixture(fdef).setUserData("tile"); } if ((tileType >= 1 && tileType <= 3) || (tileType >= 5 && tileType <= 7)) { // e bara int id = tileType; GameTileRenderer.tlz[col][row] = id; fdef.friction = 0; fdef.shape = createShape(tileSize); world.createBody(def).createFixture(fdef).setUserData("rail"); } if (tileType == 10) { // coin Cell c = new Cell(); layer.setCell(col, row, c); if (GameStats.AddTheCoin(coinID)) { GameWorld.cr.coins.add(new Vector2(x, y)); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); sensorDef.shape = createShape(tileSize); TileData tmp = new TileData(coinID, "coin"); coinID++; world.createBody(def).createFixture(sensorDef).setUserData(tmp); } else { GameWorld.cr.coins.add(null); coinID++; } } if (tileType == 9) { // coin Cell c = new Cell(); layer.setCell(col, row, c); GameWorld.cr.stars.add(new Vector2(x, y)); def.position.set((col + 0.5f) * tileSize / B2D.PPM, (row + 0.5f) * tileSize / B2D.PPM); sensorDef.shape = createShape(tileSize); TileData tmp = new TileData(starID, "star"); starID++; world.createBody(def).createFixture(sensorDef).setUserData(tmp); } } } }
public void Create() { // set tilemap file name m_MapFileName = "map/test.tmx"; // set up the tilemap m_TiledMap = new TmxMapLoader().load(m_MapFileName); m_TiledMapRenderer = new OrthogonalTiledMapRenderer(m_TiledMap, 1f); // set up the box2d physics m_PhysicsWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, 0), true); // attach contact listener to physics world m_PhysicsWorld.setContactListener(new GameContactListener(this)); // set up box2dlights m_RayHandler = new RayHandler(m_PhysicsWorld); m_RayHandler.setAmbientLight(0.0f); // add tilemap collision boxes to physics world for (int i = 0; i < m_TiledMap.getLayers().getCount(); i++) { if (m_TiledMap.getLayers().get(i) instanceof TiledMapTileLayer) { TiledMapTileLayer layer = (TiledMapTileLayer) m_TiledMap.getLayers().get(i); for (int j = 0; j < layer.getWidth(); j++) { for (int k = 0; k < layer.getHeight(); k++) { Cell cell = layer.getCell(j, k); if (cell != null) { TiledMapTile tile = cell.getTile(); if (tile != null) { MapProperties props = tile.getProperties(); if (props.containsKey("blocked")) { float worldX = j * 64 + 32; float worldY = k * 64 + 32; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.position.set(new Vector2(worldX * WORLD_TO_BOX, worldY * WORLD_TO_BOX)); Body newBody = m_PhysicsWorld.createBody(bodyDef); PolygonShape boxShape = new PolygonShape(); boxShape.setAsBox(32 * WORLD_TO_BOX, 32 * WORLD_TO_BOX); // Create a fixture definition to apply our shape to FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = boxShape; newBody.createFixture(fixtureDef); boxShape.dispose(); } if (props.containsKey("rotate")) { // flip some random tiles to break pattern if (k * j % 3 == 0) layer.getCell(j, k).setFlipVertically(true); if (k * j % 2 == 0) layer.getCell(j, k).setFlipHorizontally(true); } } } } } } } // set up artemis entity system m_ArtemisWorld = new com.artemis.World(); // add the passive systems m_SpineRenderSystem = new SpineRenderSystem(m_GameScreen); m_ArtemisWorld.setSystem(m_SpineRenderSystem, true); // add the systems m_ArtemisWorld.setSystem(new PlayerInputSystem(this)); m_ArtemisWorld.setSystem(new CameraSystem(m_GameScreen.m_Camera)); m_ArtemisWorld.setSystem(new PhysicsSystem()); m_ArtemisWorld.setSystem(new LifecycleSystem(this)); m_ArtemisWorld.setSystem(new SteeringSystem()); // init the world m_ArtemisWorld.initialize(); EntityHelper.LoadObjects( m_GameScreen, m_ArtemisWorld, m_TiledMap, m_PhysicsWorld, m_RayHandler); // add player to entity list m_PlayerEntity = new PlayerEntity(); m_PlayerEntity.AddToWorld(this); checkpointPos = new Vector2(0, 0); checkpointPos.x = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_X; checkpointPos.y = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_Y; // hud items are special cases since they needs to draw on top of border m_VialOne = new SpineComponent("map/vial", 5, 0.75f, -25); m_VialTwo = new SpineComponent("map/vial", 5, 0.65f, -5); m_VialThree = new SpineComponent("map/vial", 5, 0.75f, -50); m_WatchSpine = new SpineComponent("map/watch", 4, 0.75f, 0); if (m_GameScreen.m_Settings.m_WatchFound) { ActivateWatch(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(621 * WORLD_TO_BOX, 5961 * WORLD_TO_BOX, 0); } if (m_GameScreen.m_Settings.m_WeaponFound) { ActivateSword(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(1965 * WORLD_TO_BOX, 4842 * WORLD_TO_BOX, 0); } if (m_GameScreen.m_Settings.m_WeaponLightFound) { ActivateSwordLight(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(6390 * WORLD_TO_BOX, 6462 * WORLD_TO_BOX, 0); } }
protected void loadTileLayer(TiledMap map, Element element) { if (element.getName().equals("layer")) { String name = element.getAttribute("name", null); int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = element.getParent().getIntAttribute("tilewidth", 0); int tileHeight = element.getParent().getIntAttribute("tileheight", 0); boolean visible = element.getIntAttribute("visible", 1) == 1; float opacity = element.getFloatAttribute("opacity", 1.0f); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight); layer.setVisible(visible); layer.setOpacity(opacity); layer.setName(name); TiledMapTileSets tilesets = map.getTileSets(); Element data = element.getChildByName("data"); String encoding = data.getAttribute("encoding", null); String compression = data.getAttribute("compression", null); if (encoding == null) { // no 'encoding' attribute means that the encoding is XML throw new GdxRuntimeException("Unsupported encoding (XML) for TMX Layer Data"); } if (encoding.equals("csv")) { String[] array = data.getText().split(","); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int id = (int) Long.parseLong(array[y * width + x].trim()); final boolean flipHorizontally = ((id & FLAG_FLIP_HORIZONTALLY) != 0); final boolean flipVertically = ((id & FLAG_FLIP_VERTICALLY) != 0); final boolean flipDiagonally = ((id & FLAG_FLIP_DIAGONALLY) != 0); id = id & ~MASK_CLEAR; tilesets.getTile(id); TiledMapTile tile = tilesets.getTile(id); if (tile != null) { Cell cell = createTileLayerCell(flipHorizontally, flipVertically, flipDiagonally); cell.setTile(tile); layer.setCell(x, yUp ? height - 1 - y : y, cell); } } } } else { if (encoding.equals("base64")) { byte[] bytes = Base64Coder.decode(data.getText()); if (compression == null) { int read = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int id = unsignedByteToInt(bytes[read++]) | unsignedByteToInt(bytes[read++]) << 8 | unsignedByteToInt(bytes[read++]) << 16 | unsignedByteToInt(bytes[read++]) << 24; final boolean flipHorizontally = ((id & FLAG_FLIP_HORIZONTALLY) != 0); final boolean flipVertically = ((id & FLAG_FLIP_VERTICALLY) != 0); final boolean flipDiagonally = ((id & FLAG_FLIP_DIAGONALLY) != 0); id = id & ~MASK_CLEAR; tilesets.getTile(id); TiledMapTile tile = tilesets.getTile(id); if (tile != null) { Cell cell = createTileLayerCell(flipHorizontally, flipVertically, flipDiagonally); cell.setTile(tile); layer.setCell(x, yUp ? height - 1 - y : y, cell); } } } } else if (compression.equals("gzip")) { throw new GdxRuntimeException("GZIP compression not supported in GWT backend"); } else if (compression.equals("zlib")) { throw new GdxRuntimeException("ZLIB compression not supported in GWT backend"); } } else { // any other value of 'encoding' is one we're not aware of, probably a feature of a future // version of Tiled // or another editor throw new GdxRuntimeException( "Unrecognised encoding (" + encoding + ") for TMX Layer Data"); } } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } map.getLayers().add(layer); } }
public TiledMapTile getTile(float x, float y) { Vector2 tileIndex = getTileIndex(x, y); Cell cell = decorativeLayer.getCell((int) tileIndex.x, (int) tileIndex.y); return cell.getTile(); }
private void loadLayer(TiledMap map, Element element) { if (element.getName().equals("Layer")) { String id = element.getAttribute("Id"); String visible = element.getAttribute("Visible"); Element dimensions = element.getChildByName("Dimensions"); String layerSize = dimensions.getAttribute("LayerSize"); String tileSize = dimensions.getAttribute("TileSize"); String[] layerSizeParts = layerSize.split(" x "); int layerSizeX = Integer.parseInt(layerSizeParts[0]); int layerSizeY = Integer.parseInt(layerSizeParts[1]); String[] tileSizeParts = tileSize.split(" x "); int tileSizeX = Integer.parseInt(tileSizeParts[0]); int tileSizeY = Integer.parseInt(tileSizeParts[1]); TiledMapTileLayer layer = new TiledMapTileLayer(layerSizeX, layerSizeY, tileSizeX, tileSizeY); Element tileArray = element.getChildByName("TileArray"); Array<Element> rows = tileArray.getChildrenByName("Row"); TiledMapTileSets tilesets = map.getTileSets(); TiledMapTileSet currentTileSet = null; int firstgid = 0; int x, y; for (int row = 0, rowCount = rows.size; row < rowCount; row++) { Element currentRow = rows.get(row); y = rowCount - 1 - row; x = 0; for (int child = 0, childCount = currentRow.getChildCount(); child < childCount; child++) { Element currentChild = currentRow.getChild(child); String name = currentChild.getName(); 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")) { // Create an AnimatedTile int interval = currentChild.getInt("Interval"); Element frames = currentChild.getChildByName("Frames"); Array<StaticTiledMapTile> frameTiles = new Array<StaticTiledMapTile>(); for (int frameChild = 0, frameChildCount = frames.getChildCount(); frameChild < frameChildCount; frameChild++) { Element frame = frames.getChild(frameChild); String frameName = frame.getName(); 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"))); } } Cell cell = new Cell(); cell.setTile(new AnimatedTiledMapTile(interval / 1000f, frameTiles)); layer.setCell(x++, y, cell); // TODO: Reuse existing animated tiles } } } map.getLayers().add(layer); } }