Tilemap and memory

I am using multi instsances of Tilemaps type, all with size of the stage, the question is, if I have few tiles on each Tilemap, would that mean less memory consumption?

And how would I dispose a Tilemap effectively?

The less atlases you use, the less memory consumption you have.
To have maximum performance, try to merge all your sprites into one atlas and use only one Tilemap to have only one draw call onto your GPU.

1 Like

Would it be possible to have chunk of indices for tiles within the same Tilemap? Each tiles group within a chunk range?

You have a Tileset which is a class that should stores every sprites on your atlas (openfl-atlas does it for you, basically it just add Rectangles and stores names)

So a Tileset describes the content of your atlas (BitmapData of your atlas and where the Sprites are).
Then when you create a Tile, you pass the id of your Sprite within your atlas. If you don’t know the id, you can use openfl-atlas to retrieve it with TilesetEx.getImageID(spriteNameInYouAtlas)

You can set a default Tileset in your Tilemap. You can add as many tiles as you want.

var map:Tilemap = new Tilemap(500, 500, tileset);
map.addTile(new Tile(id, x, y, 1, 1, 0));
map.addTile(new Tile(id, x, y, 1, 1, 0));
map.addTile(new Tile(id, x, y, 1, 1, 0));
...

You can also change the id of the Tile or even the Tileset during ENTER_FRAME for example to animate or reuse.

var tile = new Tile(id);
tile.id = otherId;
tile.tileset = otherTileset;

Thanks loudo for clarification