문제

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

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top