简体   繁体   中英

Unit scale in libgdx tile maps

I'm pretty confused about the implementation of unit scales in libgdx tile maps. 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? 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.

You can achieve this with Sprites, for example, by scaling the Sprite by (1/16f) also. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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