Pergunta

I have been using this technique to alter tiles in our game, but I have been noticing quite a large loss in performance when many tiles are changed at once. I am using that technique to animate tiles on the TMX map. I was wondering if anyone else had noticed any performance issues using that method to change tmx tiles? Is there a more efficient way to alter TMX Tiles?

The only other option I can think of, to get around the performance loss, is to attach animating sprites to the TMX layer, but that does not seem like an ideal solution.

Any advice would be appreciated.

Below is the method I was referring to:

 mTestTile.setGlobalTileID(mTMXTiledMap, mGloabalIndex);

 //After changing the global ID do this       
 final int TileHeight = mTMXTiledMap.getTileHeight();
 final int TileWidth = mTMXTiledMap.getTileWidth();           
 //See TMXLayer Class line 308 (getSpriteBatchIndex)
 lTMXLayer.setIndex(mTestTile.getTileRow() * mTMXTiledMap.getTileColumns() + mTestTile.getTileColumn());
lTMXLayer.drawWithoutChecks(mTestTile.getTextureRegion(), mTestTile.getTileX(),  mTestTile.getTileY(), lTileWidth, lTileHeight, Color.WHITE_ABGR_PACKED_FLOAT);     
mTMXTiledMap.mTestTMXLayer.submit();[/syntax]

Note: I am using GLES2 Anchor_Center Branch

Foi útil?

Solução

I am not sure if you can use this, but I needed something similar. I have few objects in my TMX map that I wanted to have two frames (on/off). Instead of using map layer, I used object layer for these. I've added this code to TMXTileset class:

public ITiledTextureRegion getTiledTextureRegionFromGlobalTileID(final int pGlobalTileID, final int pTiles) {
    ITextureRegion[] regions = new ITextureRegion[pTiles];
    for (int i = 0; i < pTiles; i++) {
        regions[i] = getTextureRegionFromGlobalTileID(pGlobalTileID + i);
    }

    return new TiledTextureRegion(this.mTexture, regions);
}

I put all on/off objects to special object layer (using Tiled editor). Of course, the tileset must be organized so that the on and off frames are in sequence.

Then when I am creating the map, I iterate through these objects and create the tiled sprite. I save it to a special list for later retrieval. Then of course switching from one to another is as easy as using setCurrentTileIndex()

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top