Tilemaps sprites API

Is there any tilemaps API in PlayCanvas?
I mean something like pure canvas api (Square tilemaps implementation: Static maps - Game development | MDN) but using PlayCanvas sprites.

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

Only example I found is Procedural Levels (Procedural Levels | Learn PlayCanvas). 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?

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

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

2 Likes

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/

1 Like

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

1 Like

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

Thanks for sharing!

1 Like