简体   繁体   English

为什么libgdx新版本使用图块单元来设置相机的位置?

[英]Why libgdx new version use tile unit to set the position of the camera?

I'm trying to put the new version of libgdx 0.9.8 -> 1.0.1. 我正在尝试放置新版本的libgdx 0.9.8- > 1.0.1。

I use a tilemap and an OrthographicCamera with an OrthogonalTiledMapRenderer . 我将tilemap和OrthographicCameraOrthogonalTiledMapRenderer一起使用。

This is my camera implementation : 这是我的相机实现:

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

So when I try to move up the camera (just 2 pixels), I do this : 因此,当我尝试向上移动相机(仅2个像素)时,我这样做:

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

Unfortunately, this operation moves up the camera 2 tiles. 不幸的是,此操作将摄像机向上移动了2个图块。

How can I move my camera with only pixels ? 如何仅以像素移动相机?

Thanks. 谢谢。

By passing a unitScale of 1/128f to the renderer, and using a camera viewport of 5 x (height/128f) you are telling libgdx you want the camera units to be tiles instead of pixels. 通过将1 / 128f的unitScale传递给渲染器,并使用5 x(height / 128f)的摄影机视口,您告诉libgdx您希望摄影机单位是平铺而不是像素。

Either don't use tile dimensions for the camera and map renderer, or divide all of your pixel values by 128f to convert them to tile units. 不要为相机和地图渲染器使用图块尺寸,或者将所有像素值除以128f即可将其转换为图块单位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM