java动画仅在按下键时显示,图像在未按下键时消失
当没有按下任何键时,屏幕是空白的,我希望动画在动画的最后一个图像处停止,但当没有按下任何键时,它会消失。这是我的渲染方法
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
time += Gdx.graphics.getDeltaTime();
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)){
batch.draw(right.getKeyFrame(time, true), 100, 0);
}
if (Gdx.input.isKeyPressed(Input.Keys.LEFT))batch.draw(left.getKeyFrame(time,true),100,0);
batch.end();
}
# 1 楼答案
问题是,当右键或左键都没有被按下时,您没有调用
batch.draw(...)
你需要这样的东西:
您需要将
middle
对象替换为不按任何键时在屏幕上看到的对象