我正在使用LibGDX为Android构建一个简单的游戏(基于飞扬的鸟)。
当鸟(演员)移动时,它会将旧图像保留在屏幕上,如下所示:
我不知道为什么会这样......
这是我的GameplayScreen类(代表游戏画面)
public class GameplayScreen extends ScreenAdapter{
private FlappyBird _game;
private OrthographicCamera _camera;
private Stage _gameplayStage;
private Bird _bird;
private Image _background;
public GameplayScreen(FlappyBird game){
_game = game;
_camera = new OrthographicCamera(FlappyBird.WIDTH, FlappyBird.HEIGHT);
_gameplayStage = new Stage(new StretchViewport(FlappyBird.WIDTH, FlappyBird.HEIGHT, _camera));
_background = new Image(Assets.background);
_gameplayStage.addActor(_background);
_bird = new Bird();
_bird.setPosition(FlappyBird.WIDTH * 0.25f, FlappyBird.HEIGHT/2, Align.center);
_gameplayStage.addActor(_bird);
}
@Override
public void render(float delta){
_gameplayStage.act();
_gameplayStage.draw();
}
/*Resizes the camera when the screen is resized*/
@Override
public void resize(int width, int height){
_camera.setToOrtho(false, width, height);
Assets.batch.setProjectionMatrix(_camera.combined);
_gameplayStage.getViewport().update(width, height, true);
}
}
有人有线索吗?
答案 0 :(得分:4)
//set the background color
Gdx.gl.glClearColor(0, 0, 0, 0);
//clear
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
在渲染方法中添加上面的代码。这样做是为了清除屏幕上的帧。