不按任何键时屏幕一片空白,我希望动画停在动画的最后一个图像,但不按任何键时它会消失。这是我的渲染方法。
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();
}
最佳答案
问题是,当 RIGHT 或 LEFT 都没有被按下时,您没有调用 batch.draw(...)
。
你需要这样的东西:
if ( Gdx.input.isKeyPressed(Input.Keys.RIGHT) )
{
batch.draw(right.getKeyFrame(time, true), 100, 0);
}
else if ( Gdx.input.isKeyPressed(Input.Keys.LEFT) )
{
batch.draw(left.getKeyFrame(time, true), 100, 0);
}
else
{
batch.draw(middle.getKeyFrame(time, true), 100, 0);
}
您需要将中间
对象替换为您期望在未按下任何键时在屏幕上看到的内容。
关于java - 仅当按下按键时动画出现,不按下任何按键时图像消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38343450/