本文介绍了LibGDX-并非每帧都清洁窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用LibGDX为Android(基于飞扬的小鸟)构建一个简单的游戏.
I am using LibGDX to build a simple game for android (based on flappy bird).
碰巧,当鸟(演员)移动时,它会将旧图像保留在屏幕上,如下所示:
It happens that when the bird (actor) moves it keeps the old images on the screen, something like this:
我不知道为什么会这样...
I have no idea why this is happening...
这是我的GameplayScreen类(代表游戏屏幕)
Here is my GameplayScreen class (that represents the game screen)
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);
}
}
有人知道吗?
推荐答案
//set the background color
Gdx.gl.glClearColor(0, 0, 0, 0);
//clear
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
在您的render方法中添加上面的代码.这样做是为了清除屏幕上的框架.
Add the code above in your render method. What this does is to clear the frames on the screen.
这篇关于LibGDX-并非每帧都清洁窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!