在LibGdx中,当我使用下面的代码渲染平铺地图时,tilesMapRenderer.render()调用在一次调用后在黑色区域留下一个闪烁的图像(我通过仅在create方法中渲染测试了这个)并且我避开了能够删除它。当窗口大小改变时,这种闪烁的图像成为问题。
TiledMap tiledMap;
OrthogonalTiledMapRenderer tMR;
ExtendViewport viewPort;
@Override
public void create () {
OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, 512, 512);
viewPort = new ExtendViewport(512, 512, 512, 512, camera );
viewPort.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
tiledMap = new TmxMapLoader().load("LibGdxTutorial.tmx");
tMR = new OrthogonalTiledMapRenderer(tiledMap);
}
@Override
public void render () {
viewPort.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
tMR.setView((OrthographicCamera) viewPort.getCamera());
tMR.render();
}
This is the default window you get after pressing run
This is the window after I dragged the right side out
第二张照片右侧的地图图片是完整正确的地图。左侧的地图图像是图像后闪烁(它显示为满,因为它是一帧)。任何帮助将不胜感激,谢谢。
答案 0 :(得分:2)
您需要每帧清除屏幕。这在渲染方法中发生,应该在开始绘制之前使用。
Gdx.gl.glClearColor(0f,0f,0f,1); // set the clear color
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // clear the screen with the given color.
.. draw next frame ..