动画只在按键时出现,不按键时图像消失
Animation appears only when key is pressed, image disappears when no key is pressed
不按时黑屏,我想让动画停在动画的最后一张图,但是不按时就消失了。这是我的渲染方法。
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);
}
您需要将 middle
对象替换为您希望在未按下任何键时在屏幕上看到的内容。
不按时黑屏,我想让动画停在动画的最后一张图,但是不按时就消失了。这是我的渲染方法。
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);
}
您需要将 middle
对象替换为您希望在未按下任何键时在屏幕上看到的内容。