Tilemaps sprites API


#1

Is there any tilemaps API in PlayCanvas?
I mean something like pure canvas api (https://developer.mozilla.org/en-US/docs/Games/Techniques/Tilemaps/Square_tilemaps_implementation%3A_Static_maps) but using PlayCanvas sprites.

Input: tilesets and tilemap layers. Output: rendered sprite.

Only example I found is Procedural Levels (https://developer.playcanvas.com/en/tutorials/procedural-levels/). It clones entities - looks like it can have not very good performance on weak devices (e.g. mobile). Is that right or maye there are some engine optimisations under the hood?


#2

Your best bet is to leverage Texture Atlases for that:

Here is the relevant entry to the manual and the available API:

https://developer.playcanvas.com/en/user-manual/2D/

https://developer.playcanvas.com/en/api/pc.TextureAtlas.html


#3

I think the OP is wanting to render/draw the tilemap background in a single/as few as draw calls as possible


#4

Right! Batching is not available through the editor for sprites/elements, it was removed at some point, temporary I think, due to some issues with the drawing order.

But the property is available through code for entities having a sprite component. You can set the batchGroupId property to a dynamic or static batching group ID to see if the batcher will pick them up. I haven’t tried it myself but it might work:

https://developer.playcanvas.com/en/api/pc.SpriteComponent.html#batchGroupId

Here you can read more about how PlayCanvas batching works:

https://developer.playcanvas.com/en/user-manual/optimization/batching/


Sprite Batching
#5

Leonidas, thanks for response. I’ll try batch group id later.

By the way, I wrote simple test shader for tilemapping. Maybe it will be usefull as a starting point for someone else
https://playcanvas.com/editor/project/646085


#6

Nice, that’s a very peculiar way of rendering an ISO grid in a pixel shader.

Thanks for sharing!