4
\$\begingroup\$

Is it possible to rotate my sprite in LibGDX?enter image description here

public class Flame {
    private static final int FRAME_COLS = 6;
    private static final int FRAME_ROWS = 1;

    private Animation flameAnimation;
    private Texture flameSheet;
    private TextureRegion[] flameFrames;
    private SpriteBatch spriteBatch;
    private TextureRegion currentFrame;

    private float stateTime;

    private int xFlame;
    private int yFlame;
    private float rotation;

    /*
        Some code here
    */

    public void draw(){
        stateTime += Gdx.graphics.getDeltaTime();
        currentFrame = flameAnimation.getKeyFrame(stateTime, true);
        /*
          I also try currentFrame.flip(true, false); // but this doesn't work
        */
        spriteBatch.begin();
        spriteBatch.draw(currentFrame, xFlame, yFlame);
        spriteBatch.end();
   }
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is not possible by rotation, but libGDX has an option to draw flipped, which is what you want. \$\endgroup\$
    – ashes999
    Oct 11, 2014 at 23:20

1 Answer 1

6
\$\begingroup\$

From LibGDX's docs:

spriteBatch.draw(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)

Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.

Set flipX as true to get your desired result

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .