I’m learning how to use Defold and I’ve been looking into Atlas usage to improve memory management. If I understood correctly, Atlases are used to “compile” multiple images into a single sheet in order to optimize memory usage.
At this point, a question came to mind about using them in the most efficient and correct way possible: what criteria should be used when deciding to create multiple Atlases for a game’s sprites?
For example, is it correct to create different Atlases to keep sprites organized (such as one Atlas for the large background image, one for all the player sprites, one for enemies, one for buttons, etc.), or is it better to pack as many sprites as possible into a single Atlas with the mindset of: “Can this sprite appear in this level? If yes, then it goes into the same Atlas”?
Thanks in advance for any tips that will help me use this fantastic engine properly.
If a project has few and small enough sprites to fit into a single 4096x4096 atlas, then using a single atlas is totally fine. Or to support very old devices 2048x2048. For larger atlases, you should split them.
You should group them depending on which sprites are rendered at the same time, but more specifically, depending on in which order they are rendered.
Imagine you have 50 characters, with body sprites, and face sprites, with the face having a z-value 0.001 higher than the body to be rendered above it, and characters spaced 0.01 to not clip. Then the render script will render them body_1 → face_1 → body_2 → face_2, and so on. Everytime the renderer has to switch the atlas, it needs a new draw call, making performance worse. So if you have one atlas for bodies, and one for faces, that would be 100 draw calls. 50 atlases with one body and face for each character would be 50 draw calls. Everything in one atlas would be only 1 draw call.