mcfly soft
mcfly soft

Reputation: 11645

create multiple textures with rotation of original texture and save them in a list

Not sure if I am on the right way.

I have a smal texture which I draw multiple times (1000). But I like to have them with different rotations (around 10) for that texture. So I thought to rotate the textures and save the in a list (10) for the reuse (performance).

When my approach is good, how can I rotate an original texture and store it to a new texture (in memory during start) ?

Upvotes: 0

Views: 139

Answers (1)

icarumbas
icarumbas

Reputation: 1805

You can use Sprite class that wraps a Texture and provides many useful methods to work with it. For example: scaling, rotating.

So you will have one Texture instance and 10 sprites.

Texture texture = new Texture("path.png");

for (int i = 0; i < 10; i++) {
    Sprite sprite = new Sprite(texture);
    sprite.setSize(..);
    sprite.setRotation(..);
    someList.add(sprite);
}

And then you can just select which sprite you want set it's position and draw it:

sprite.draw(spriteBatch);

Upvotes: 1

Related Questions