gpt4 book ai didi

rotation - LibGDX - 自身旋转 SpriteBatch

转载 作者:行者123 更新时间:2023-12-01 21:14:07 28 4
gpt4 key购买 nike

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

最佳答案

您正在使用 SpriteBatch 绘制纹理。纹理不支持旋转。我建议Sprite类(class)可能更适合您想做的事情。以下是您可以执行的操作的粗略概述...请参阅 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);
}

关于rotation - LibGDX - 自身旋转 SpriteBatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15771915/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com