我的2D平台游戏的虚拟大小为800x480,我使用StretchViewport
来设置Stage。
我按照以下方式设置游戏相机:
camera = new BoundedCamera(18, 10, map.width, map.height);
BoundedCamera
只是在 OrthographicCamera
的基础上添加了一些额外的代码,使得当玩家移动到地图边缘时地图仍然保持在屏幕内。
在 render()
方法中我这样做:
camera.setPosition(player.getX(), player.getY());
camera.update();
tiledRenderer.setView(camera);
tiledRenderer.render();
一切正常。现在我想要实现一个小地图,我希望将其显示在(0, 380)处,大小为(100, 100)。因此,我创建了第二个相机和一个ScalingViewport
:
minimapCamera = new OrthographicCamera(18, 10);
minimapViewport = new ScalingViewport(Scaling.none, map.width, map.height, minimapCamera);
minimapViewport.setScreenBounds(0, 380, 100, 100);
对于渲染,我执行以下操作:
public void renderMinimap()
{
minimapViewport.apply();
minimapBatch.begin();
minimapCamera.position.set(player.getX(), player.getY());
minimapCamera.update();
minimapRenderer.setView(minimapCamera);
minimapRenderer();
minimapBatch.end();
level.getStage().getViewport().apply();
}
然而,以上方法无法使小地图在视口范围内被“裁剪”。小地图层会在视口边界的左下方略微绘制。
我做错了什么?