Search code examples
javaandroidlibgdxgame-enginegame-development

LibGDX Drawing text to top-left corner


I'm new to libgdx and followed a tutorial to make a simple game, now i wanted to extend a small part myself that is adding an fps counter in the top left corner of the screen

The code i used is copy-pasted from https://github.com/libgdx/libgdx/wiki/A-Simple-Game (scroll to end for the final code)

In render method just after clearing the screen and updating the camera i did something like this

font.draw(batch, String.valueOf(Gdx.graphics.getFramesPerSecond()), 0, 480);

(I added a font field initialized with new BitmapFont(); and obviously i wrapped the text drawing in a batch.begin() and end)

The game crashes on start, but i don't get it

From my mind it works this way

x is 0 because i want the start of the left corner

480 y to draw at the top, the camera is of height 480 so that is top-left corner this way.

Now the question is am i misunderstanding the coordinate system or if not then what's exactly wrong in my code? I'm testing on Android btw.


Solution

  • Found the issue, the font wasn't being bundled properly, i extracted the font files from the gdx jar file and placed it to my own assets folder and it works now.