2
votes

enter image description here

I would like to rotate this SpriteBatch on itself upon clicking on a button

@Override
public void render() {

    SpriteBatch batch = new SpriteBatch();

    batch.begin();
    batch.draw(gemTexture, 10, 10, 100, 100);
    batch.end();

    if (Gdx.input.isTouched()) {
        rotateRight();
    }

}

private void rotateRight() {
// How do I rotate it to look like 
}

enter image description here

1
Something similar to this? stackoverflow.com/questions/9445035/…Robb

1 Answers

9
votes

You're drawing a Texture using a SpriteBatch. A Texture doesn't support rotation. I suggest that the Sprite class might be better suited for what you are trying to do. Here's a rough outline of what you might do... see the Sprite javadoc for more detail.

private void createGemSprite() {
    gemSprite = new Sprite(gemTexture);
    gemSprite.setPosition(10, 10);
}

@Override
public void render() {

    SpriteBatch batch = new SpriteBatch();

    batch.begin();
    gemSprite.draw(batch);
    batch.end();

    if (Gdx.input.isTouched()) {
        rotateRight();
    }
}

private void rotateRight() {
    gemSprite.setRotation(gemSprite.getRotation() - 90);
}