Atlas from single image

I would like to be able to use a single pre-composed image as source of an atlas and specify animations through coordinates in that image. The benefit would be that it allows for a single texture source for a large number of sprites (thus optimizing batch rendering) while allowing animations to have the same names.

Usecase:
You want to have several different enemies that all have the animations “walk”, “attack” and “idle”. Now you need to create a separate atlas or tilesource for each enemy in order to have the same animation name across all of them. It also means each enemy would create an additional draw call. If they all shared the same texture they would all be able to be drawn in a single draw call.

1 Like

If you add a level of indirection in Lua then you can achieve this. Make a tilesource with all animation sets named according to a scheme: “walk_enemy1”, “walk_enemy2” etc. In Lua, concatenate the anim name depending on enemy type.

Yes, but then comes the problem of strings being passed as hashes as soon as they are properties etc. So that means I would have to have separate scripts for all enemies since the string value can’t be set as a property on the script responsible for animation (if the enemy type “goblin” is set as a property then I have no way of concatenating with that since it is no longer a string but a hash).

I see. How about a lookup table with hash keys to a set of animation names for that key?

That is ok when you have a limited number of enemies, but in our case that becomes very hard to maintain and makes it much harder for non-coders to be involved

Sure, I understand. We’ll think about it and see if there’s a good way to solve this.

Thanks!
Also having a single image atlas has the added benefit of reducing the number of files in a project which makes it easier to maintain.