简体   繁体   English

libgdx切片地图中的单位比例

[英]Unit scale in libgdx tile maps

I'm pretty confused about the implementation of unit scales in libgdx tile maps. 我对libgdx磁贴图中的单位比例的实现感到非常困惑。 For example if I specify my unit scale to be 1/16f and have an actor move from (0,0) to (0,1) in my logical world, will the sprite actually move 16 pixels? 例如,如果我将单位比例指定为1 / 16f,并且在逻辑世界中有一个actor从(0,0)移至(0,1),则精灵实际上会移动16个像素吗? And does this mean an actor can only be directly on a tile? 这是否意味着演员只能直接在图块上?

If you choose 1/16f as unit scale for your map, all your coordinates in the map will be tile-based (so to speak) instead of pixel-based. 如果您选择1 / 16f作为地图的单位比例,则地图中的所有坐标都将基于图块(可以这么说),而不是基于像素。

You can achieve this with Sprites, for example, by scaling the Sprite by (1/16f) also. 您可以使用Sprites实现此目的,例如,也可以将Sprite缩放为(1 / 16f)。 Now all coordinates (and the size of the sprite) is scaled to fit the tile map. 现在,所有坐标(以及子图形的大小)都已缩放以适合图块地图。

Remember to set the correct projection for your batch-renderer before you do batch-drawing, so that the coordinates are converted correctly. 在进行批绘制之前,请记住为批渲染器设置正确的投影,以便正确转换坐标。 Otherwise you will have to figure out where the camera is and adjust your drawing manually. 否则,您将不得不找出相机的位置并手动调整绘图。 batch.setProjectionMatrix(camera.combined) should work. batch.setProjectionMatrix(camera.combined)应该可以工作。

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

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