下面的代码一直呈现黑屏...任何想法为什么?我将base.tmx放在桌面文件夹中并使用平铺创建它。我把.tmx放在错误的文件夹中了吗?它让我疯狂。
public class GameScreen extends ScreenAdapter {
OrthographicCamera camera;
TiledMap tiledmap;
TiledMapRenderer tiledMapRenderer;
public void show()
{
camera=new OrthographicCamera();
camera.setToOrtho(false);
camera.update();
tiledmap= new TmxMapLoader().load("base.tmx");
tiledMapRenderer=new OrthogonalTiledMapRenderer(tiledmap);
}
public void render()
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
}
}
答案 0 :(得分:0)
您没有设置相机的宽度和高度。您还应该使用delta参数正确覆盖ScreenAdapter的render方法。这是您的代码的更新版本:
public class GameScreen extends ScreenAdapter {
OrthographicCamera camera;
TiledMap tiledmap;
TiledMapRenderer tiledMapRenderer;
public void show()
{
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera=new OrthographicCamera();
camera.setToOrtho(false,w,h);
camera.update();
tiledmap= new TmxMapLoader().load("base.tmx");
tiledMapRenderer=new OrthogonalTiledMapRenderer(tiledmap);
}
public void render(float delta)
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
}
}