-1

In my libGdx project,I created a sprite from texture atlas,using createSprite(). I want to implement the sprite as rotated. How can I do it?Here is my Code:

 reelSprite = atlas.createSprite("reel"); 

Inside render():

for (Wall lWalls : leftWalls){
        reelSprite.setOrigin(lWalls.getX(), lWalls.getY());
        reelSprite.setRotation(180);

    batch.draw(reelSprite, lWalls.getX(), lWalls.getY());
    }

This code is not working.Please tell me what wrong I did.

Niranjana
  • 514
  • 5
  • 23
  • Please try to achieve your goals yourself first before asking a question. Then, in the question explain what you tried, with code preferably, and what's not working. – DavidS Dec 01 '16 at 18:57

3 Answers3

0

You should use setRotation before you draw the sprite:

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setRotation-float-

And even before that set rotation point:

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setOrigin-float-float-

MilanG
  • 6,994
  • 2
  • 35
  • 64
0
float rotate = 0;
rotate += (sprite.getRotation() - 40) * Gdx.graphics.getDeltaTime();
      if(Math.abs(rotate) > 10) // change the number to set the rotation power cap
            {
                rotate = -10;
            }
   sprite.rotate(rotate);
Gagiu Filip
  • 188
  • 1
  • 10
0

I changed the code like this...

for (Wall lWalls : leftWalls){
        reelSprite1.setPosition(lWalls.getX(), lWalls.getY());
        reelSprite1.setOrigin(reelSprite1.getWidth()/2,reelSprite1.getHeight()/2);
        reelSprite1.setRotation(180);
        reelSprite1.draw(batch);

then it worked.

Niranjana
  • 514
  • 5
  • 23