Question

I have looked into the SuperKaolio example on Libgdx github repo. It is basically a test for integrating Tiled maps with Libgdx. They are using the unit scale 1/16 and if I have understood it correctly it means that the world no longer is based on a grid of pixels but on a grid of units (each 16 pixels wide). This is the code and comment in the example:

// load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);

I am basically wondering why you would want to do that. I only got problems doing it and can't see any obvious advantages.

For example, one problem I had was adding a BitMap font. It didn't scale at all with the background and one pixel in the font occupied an entire unit. Image here.

I'm using this code for drawing the font. It's a standard 14 points arial font included in libgdx

BitmapFont font = new BitmapFont();
font.setColor(Color.YELLOW);

public void draw(){
   spriteBatch.begin();
   font.draw(batch, "Score: " + thescore, camera.position.x, 10f);
   spriteBatch.end();
}
Was it helpful?

Solution

I assume there is a handy reason to have a 1/16th scale for tiled maps (perhaps for doing computations on which tile is being hit or changing tiles (they're at handy whole-number indices).

Anyway, regardless of what transformation (and thus what "camera" and thus what projection matrix) is used for rendering your tiles, you can use a different camera for your UI.

Look at the Superjumper demo, and see it uses a separate "guiCam" to render the "GUI" elements (pause button, game over text, etc). The WorldRenderer has its own camera that uses world-space coordinates to update and display the world.

This way you can use the appropriate coordinates for each aspect of your display.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top