I am refactoring my small RPGs I developed in libgdx.
I got a general question how to use the texture atlas right. I got like 100actors with around 10 Kinds of Sprites. Current i don't use an atlas but I'd like to to increase the renderingperformance since this is the only thing that does take long inside if my game loop.(got around 100binds and 15 rendercalls..)
So it took a look at the TextureAtlas
Class link to git and was wondering how I get more performance out of It. If I get a sprite of it with the right texture I do get a copy so I still would switch the OpenGL binding right? So that wouldn't be a better solution a special if I have like 100 actors all with it's own sprite or am I wrong with it and I just didn't get that right?
The Atlas itself does recommend not to call the getsprite
multiple times but I would need to do so, so that every actor has it's own sprite with a own status.
Maybe you could give me a little example how I use multiple sprites from one atlas without switching the binding of OpenGL. That should be the reason to use the atlas but I don't get it at the moment.
No, you get the TextureRegion of it. (Sprite is a more specialized TextureRegion).
So when you draw all your sprites, If they are from the same TextureAtlas, they will only need one draw.
Just use TextureAtlas#createSprite:
When you draw them, for example like this:
If the 3 sprites are from the same TextureAtlas, they will only flush the batch once.
Edit
A TextureRegion is only the coordinates and size (a rectangle) referencing to a Texture(Atlas). Dont worry, the Texture isnt copied. Its only one, doesnt matter how many sprites you create from it :)