我想在逆时针方向不断旋转环形图像这是我的代码
public class SpriteSheet extends ApplicationAdapter {
Stage stage;
@Override
public void create () {
stage=new Stage(new ScreenViewport());
Group group=new Group();
Image background =new Image(new Texture(Gdx.files.internal("background.png")));
Image button=new Image(new Texture(Gdx.files.internal("btn.png")));
Image ring=new Image(new Texture(Gdx.files.internal("ring2.png")));
background.setName("background");
button.setName("button");
ring.setName("ring");
group.addActor(background);
group.addActor(button);
group.addActor(ring);
stage.addActor(group);
background.setPosition(Gdx.graphics.getWidth()/2-background.getWidth()/2,Gdx.graphics.getHeight()/2-background.getHeight()/2);
button.setPosition(Gdx.graphics.getWidth()/2-button.getWidth()/2,Gdx.graphics.getHeight()/2-button.getHeight()/2);
ring.setPosition(255,105);
ring.setOrigin(255f,105f);
ring.rotateBy(2f); // I need continuous rotation here
}
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
}
答案 0 :(得分:4)
我想Actions
正是你要找的
可以将Action
添加到Actor
(和子类),它们将在act(delta)
的{{1}}方法内执行。
在您的情况下,您可以使用Actor
并使用Actions.rotateBy(float rotationAmount, float duration)
让它永远重复。
所以你的最终代码应如下所示:
Actions.repeat(RepeatAction.FOREVER, rotateAction)
其中ring.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(rotation, duration)));
是旋转量(我猜是度数,但我不确定),而rotation
是旋转给定量所需的时间(以秒为单位)。< / p>