Java 如何以规定的速度连续旋转精灵?以及关于游戏编程的一般问题
我有一个图像被渲染:Java 如何以规定的速度连续旋转精灵?以及关于游戏编程的一般问题,java,android,libgdx,Java,Android,Libgdx,我有一个图像被渲染: public void render(float delta) { batch.begin(); batch.draw(new Sprite(new Texture("img1.png"), 64, 64), x, y); batch.end() 使用X和Y根据屏幕的分辨率将精灵定位在屏幕中央。 我知道我可以用它来旋转,但我如何连续旋转呢?我想我需要以某种方式使用增量时间,例如,x+=50*Gdx.graphics.getDeltaTime()但这
public void render(float delta) {
batch.begin();
batch.draw(new Sprite(new Texture("img1.png"), 64, 64), x, y);
batch.end()
使用X和Y根据屏幕的分辨率将精灵定位在屏幕中央。
x+=50*Gdx.graphics.getDeltaTime()代码>但这不会连续旋转它。图像显示一帧,然后跳转到其他位置显示一帧(看起来像是逐帧平移)
我是新手,所以我希望这些问题有意义。用这种方式永远旋转你的精灵
public class TestGame extends Game {
SpriteBatch spriteBatch;
Sprite ball;
Texture ballTex;
private int spriteRotationSpeed=1;
@Override
public void create() {
spriteBatch=new SpriteBatch();
ballTex=new Texture("image/bone.png");
ball=new Sprite(ballTex);
ball.setSize(50,50);
ball.setOrigin(25,25);
ball.setPosition(0,0);
}
@Override
public void render() {
super.render();
Gdx.gl.glClearColor(1,1,1,1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
ball.draw(spriteBatch);
spriteBatch.end();
rotateSprite();
}
private void rotateSprite(){
float rotation=ball.getRotation();
rotation+=spriteRotationSpeed;
if(rotation>360)
rotation-=360;
ball.setRotation(rotation);
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void dispose() {
super.dispose();
ballTex.dispose();
spriteBatch.dispose();
}
}
没有任何批处理的方法。绘制(精灵,x,y);其中精灵是精灵类的对象。你的精灵是纹理对象还是纹理区域?它是纹理对象。我编辑了这篇文章,现在应该更清楚了。