LibGDX - 自己旋转SpriteBatch

时间:2013-04-02 18:45:21

标签: rotation libgdx spritebatch

enter image description here

我希望点击按钮后自动旋转 SpriteBatch

@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 个答案:

答案 0 :(得分:9)

您正在使用SpriteBatch绘制纹理。纹理不支持旋转。我建议Sprite类可能更适合你想做的事情。以下是您可能会做的大致概述...有关详细信息,请参阅Sprite javadoc

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);
}