@Override
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
sprite.setProjectionMatrix(camera.combined);
mLevel.getTiledMapRenderer().getProjectionMatrix().set(camera.combined);
Vector3 tmp = new Vector3();
tmp.set(0, 0, 0);
camera.unproject(tmp);
mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight);
sprite.begin();
...
sprite.end();
}
这是我在启动桌面版本时得到的:
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1. Because at most 1 elements can be returned, a buffer with at least 1 elements is required, regardless of actual returned element count
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:230)
at org.lwjgl.opengl.GL15.glBufferData(GL15.java:141)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glBufferData(LwjglGL20.java:93)
at com.badlogic.gdx.graphics.glutils.VertexBufferObject.bind(VertexBufferObject.java:208)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:268)
at com.badlogic.gdx.graphics.g2d.SpriteCache.begin(SpriteCache.java:868)
at com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer.render(TileMapRenderer.java:336)
at com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer.render(TileMapRenderer.java:286)
at com.crunsh.libgdx.screens.GameScreen.render(GameScreen.java:102)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
我已经尝试过这个 tuto和这个,我在同一行得到了同样的错误mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight);
。
编辑:我刚刚注意到我的 .tmx 文件的数据是由平铺地图编辑器自动编码的,所以我只是停用了它,但仍然得到同样的错误。
如果我复制/粘贴这个项目(我的意思是整个项目,不仅是 render() 方法)它可以工作,但是当我尝试在我自己的项目中加载我自己的地图时它只会崩溃......
所以在那之后我决定render()
通过像我之前给出的链接并使用TiledMapHelper class
作者提供的那样来简化我的方法,所以现在有我的render()
方法:
mHelper.getCamera().update();
mHelper.render();
仍然crashiiiiiiiiiiiiiiiingg .....
如果有人可以请提供一些帮助,将不胜感激,因为atm我真的要疯了!