Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

Libgdx, tiled map – how to reload layer?

$
0
0

In the simple platform game I’m making, when player collects coin, its cell is set to null. Is it possible to recover all cells from layer “coins” after player dies? I have tried multiple things but none of them worked :/

Here is part of code responsible for collecting coins:

for (Rectangle coins : coins) {
        TiledMapTileLayer layer_coins = (TiledMapTileLayer)map.getLayers().get("coins");
        if(dotRect.overlaps(coins)){
            layer_coins.setCell((int)coins.x, (int)coins.y, null);
            coinsN++;
            Sounds.playCoin();
        }
    }

But when player dies and re-spawns, there are no coins if he collected them before. I tried reloading the map – it works fine, but loading after every death is unacceptable – it takes a lot of time.

EDIT: Now I have another problem, with loading TiledMapTile to put into cell…

TiledMapTile coinTile;

public void show() {
    TextureRegion mapTexture1Region = new TextureRegion(mapTexture1, 32, 0, 16, 16);
    coinTile.setTextureRegion(mapTexture1Region);
}

It gives me NullPointerException, and I have no idea why :/


Viewing all articles
Browse latest Browse all 434

Trending Articles