【问题标题】:Why libgdx new version use tile unit to set the position of the camera?为什么 libgdx 新版本使用 tile 单元来设置相机的位置?
【发布时间】:2014-06-11 08:35:37
【问题描述】:

我正在尝试将新版本的 libgdx 0.9.8 -> 1.0.1。

我使用一个 tilemap 和一个 OrthographicCamera 和一个 OrthogonalTiledMapRenderer

这是我的相机实现:

map = tileMapHelper.getMap();
renderer = new OrthogonalTiledMapRenderer(map, 1/128f);
camera = new OrthographicCamera(width, height);
camera.setToOrtho(false, 5, (float)(height/128f));

所以当我尝试向上移动相机(仅 2 个像素)时,我会这样做:

camera.position.set(camera.position.x, camera.position.y + 2, 0);

不幸的是,此操作将相机向上移动了 2 格。

如何仅用像素移动相机?

谢谢。

【问题讨论】:

  • 我假设您必须操纵相机的视口。
  • 谢谢!我可以选择哪个视口?你能解释一下他们的角色吗?

标签: java libgdx


【解决方案1】:

通过将 1/128f 的 unitScale 传递给渲染器,并使用 5 x(高度/128f)的相机视口,您就是在告诉 libgdx 您希望相机单位是平铺而不是像素。

要么不要为相机和地图渲染器使用平铺尺寸,要么将所有像素值除以 128f 以将它们转换为平铺单位。

【讨论】:

    猜你喜欢
    • 2017-04-04
    • 1970-01-01
    • 2017-11-10
    • 2013-05-06
    • 2014-03-20
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多