我有一个完全正常的冒险游戏项目,但是如果我更改了Tiled Map(使用Tiled创建),则会引发BufferOverflowException。
Exception in thread "LWJGL Application" java.nio.BufferOverflowException
at java.nio.DirectFloatBufferU.put(DirectFloatBufferU.java:363)
at com.badlogic.gdx.graphics.g2d.SpriteCache.add(SpriteCache.java:259)
at com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer.renderTileLayer(OrthoCachedTiledMapRenderer.java:353)
at com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer.render(OrthoCachedTiledMapRenderer.java:132)
at entities.TilemapActor.draw(TilemapActor.java:76)
at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:110)
at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:57)
at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:128)
at screen.BaseScreen.render(BaseScreen.java:51)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
所以这是TilemapActor的draw()-方法,在该方法中抛出异常:
public void draw(Batch batch, float parentAlpha) {
//adjust tiled camera to be stay in sync with the game camera
Camera mainCamera = getStage().getCamera();
tiledCamera.position.x = mainCamera.position.x;
tiledCamera.position.y = mainCamera.position.y;
tiledCamera.update();
tiledMapRenderer.setView(tiledCamera);
//ned to force the batch order otherwise it is batched and redered last
batch.end();
tiledMapRenderer.render();
batch.begin();
}
最后是BaseScreen类的render()-方法:
public void render(float dt) {
uiStage.act(dt);
mainStage.act(dt);
update(dt);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
mainStage.draw();
uiStage.draw();
}
我平铺的地图是60 * 60的图块,图块大小为16 * 16,所以整个地图大960 * 960px。
正在工作的地图是40 * 40瓦片,瓦片大小为32 * 32,因此是1280 * 1280px。
我不明白,为什么较大的Map有效而较小的Map无法正常工作 任何帮助将不胜感激。
最诚挚的问候
DKJ1337