Libgdx - 渲染tilesmap(tmx)的问题

时间:2017-05-25 23:21:18

标签: android mobile libgdx

当我滚动相机时,左侧会在屏幕退出前删除一些图像。

为什么会这样?

我使用平铺地图编辑器,平铺大小为32.我尝试使用视口并得到同样的问题。我尝试了太小的地图和同样的问题。

我的代码和问题的gif:

public class MyGdxGame extends ApplicationAdapter implements InputProcessor {

private TiledMap tiledMap;
private OrthographicCamera camera;
private OrthogonalTiledMapRenderer renderer;

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    tiledMap = new TmxMapLoader().load("aventurax.tmx");
    renderer = new OrthogonalTiledMapRenderer(tiledMap);

    float propEsc = h/w;
    camera = new OrthographicCamera();
    camera.setToOrtho(false, w * propEsc, mapPixelHeight);
    camera.update();
    Gdx.input.setInputProcessor(this);
}

@Override
public void render() {
    Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    renderer.setView(camera);
    renderer.render();
}

@Override
public void dispose() {
    tiledMap.dispose();
}

@Override
public boolean keyUp(int keycode) {
    if(keycode == Input.Keys.LEFT)
        camera.translate(-32,0);
    if(keycode == Input.Keys.RIGHT)
        camera.translate(32,0);
    return false;
}

enter image description here

0 个答案:

没有答案