سؤال

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.

هل كانت مفيدة؟

المحلول

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?

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.

how do I achieve that To get multiple sprites with same texture region of the atlas without New binding when rendering?

Just use TextureAtlas#createSprite:

sprite = textureatlas.createSprite("example");

When you draw them, for example like this:

batch.begin();
sprite.draw(batch)
sprite2.draw(batch);
sprite3.draw(batch);
batch.end();

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 :)

نصائح أخرى

You change the texture co-ordinates on the vertices of your object to move where they are pointing in the texture atlas. By setting up your objects correctly you have one large texture shared between lots of objects rather than lots of small objects and lots of small textures.

There is no need to resend the texture to the graphics card etc when things change, you just move the texture co-ordinates of the object to point to the new section of the atlas that you want them to point to.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top