我在平铺地图渲染方面遇到问题。我不知道为什么OrthogonalMapRenderer不起作用。
构造函数:
this.batch = new SpriteBatch();
Gdx.graphics.setVSync(true);
this.cam = new OrthographicCamera();
this.viewport = new StretchViewport(Main.WIDTH / Main.PPM, Main.HEIGHT / Main.PPM, this.cam);
this.shapeRenderer = new ShapeRenderer();
this.world = new World(new Vector2(0 , 0) , true);
this.b2Renderer = new Box2DDebugRenderer();
this.wBuilder = new WorldBuilder(this.world , this.cam);
Gdx.input.setInputProcessor(new InputMultiplexer());
this.map = new TmxMapLoader().load("maps/chamber/chamber.tmx");
this.mapRenderer = new OrthogonalTiledMapRenderer(this.map , 1 / Main.PPM);
this.cam.position.set(this.viewport.getWorldWidth() / 2 , this.viewport.getWorldHeight() / 2 , 0);
更新方法:
this.cam.update();
this.world.step(1f / 60, 2, 5);
this.mapRenderer.setView(this.cam);
渲染:
this.update(delta);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
this.mapRenderer.render();
this.shapeRenderer.setProjectionMatrix(this.cam.combined);
this.batch.setProjectionMatrix(this.cam.combined);
this.shapeRenderer.begin(ShapeType.Filled);
// draw some shapes
this.shapeRenderer.end();
this.batch.begin();
this.drawB2();
this.batch.end();
我检查了一下,它应该很好,程序可以看到地图图层和对象,但是无法渲染它。我确信所有地图文件都没有错误。