Java – libgdx: how to animate on an isometric tile map?

I have some questions about libgdx and Pingpu map

I can use isometric tiled maprenderer as a renderer and orthographic camera to load isometrics from resources to display maps (all work is described in the wiki page) I can also programmatically fill in some blocks on the map layer, but when I try to use animatedtiledmaptile, my problem arises:

map = new TmxMapLoader().load(...);

    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().getLayer("layer1");
    TiledMapTileSet tileset =  map.getTileSets().getTileSet("tileset1");
    TiledMapTile grassTile =  tileset.getTile(4);
    TiledMapTile rockTile =  tileset.getTile(6);

    Array<StaticTiledMapTile> playerTileArr = new Array<StaticTiledMapTile>();
    playerTileArr.add((StaticTiledMapTile)tileset.getTile(7));
    playerTileArr.add((StaticTiledMapTile)tileset.getTile(8));

    Cell grass = new Cell();
    grass.setTile(grassTile);

    Cell player = new Cell();
    player.setTile(new AnimatedTiledMapTile(0.1f,playerTileArr));

    layer.setCell(0,grass);  // <--- This works.
    layer.setCell(0,1,player); // <--- When I try this,it causes 
                                //      a NullPointerException.

    renderer = IsometricTiledMapRenderer(map,1 / 30f);
    ...

Can I help you? I found an example of the use of animatedtiledmaptile for tidemaploader, but I know I'm using a "tiled map" (not a "tidal map") But can someone explain how I animate on specific tiles?

Solution

I've been looking for myself

The best guess is that your tile group doesn't have 7 or 8 tiles

I get the following code:

TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    TiledMapTileSet tileset = map.getTileSets().getTileSet(0);

    Array<StaticTiledMapTile> at = new Array<StaticTiledMapTile>();
    if (tileset.getTile(0) != null) at.add((StaticTiledMapTile) tileset.getTile(0));
    if (tileset.getTile(1) != null) at.add((StaticTiledMapTile) tileset.getTile(1));
    if (tileset.getTile(2) != null) at.add((StaticTiledMapTile) tileset.getTile(2));
    if (tileset.getTile(3) != null) at.add((StaticTiledMapTile) tileset.getTile(3));

    layer.getCell(2,2).setTile(new AnimatedTiledMapTile(0.3f,at));

Only gettile (1) and gettile (2) are= Null – I only have 2 tiles (my trouble is that gettile (0) is not the first tile getTile(1)!)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>