在相机中移动tilemap

时间:2014-08-27 08:41:43

标签: java libgdx

我有一台渲染TiledMap的相机。

我想模拟垂直滚动,向下移动相机内的平铺地图(相机保持坚固)。

我怎样才能做到这一点?

修改 在create方法

map=new TmxMapLoader().load("Map.tmx");
this.renderer=new OrthogonalTiledMapRenderer(map);
this.camera=new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
this.camera.translate(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
this.camera.update();

在渲染方法

this.renderer.setView(camera);
this.renderer.render();
camera.update();

1 个答案:

答案 0 :(得分:0)

您可以创建第二个摄像头,使用它渲染拼贴,并仅移动此摄像头:

创建方法:

this.scrollingCamera =new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
this.scrollingCamera.translate(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
this.scrollingCamera.update();

然后,在渲染过程中:

this.renderer.setView(scrollingCamera);
this.renderer.render(); // Render tiles
this.scrollingCamera.translate(SCROLLING_SPEED.X, SCROLLING_SPEED.Y);
this.scrollingCamera.update();

this.renderer.setView(camera);
// Render other stuff
camera.update();
相关问题