Bitmap Font Displays in Center Always Without Coding it Manually (Fix Coordinate Problem onText)

Posted by David Dimalanta on Game Development See other posts from Game Development or by David Dimalanta
Published on 2012-12-18T06:53:57Z Indexed on 2012/12/18 11:13 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

Is there a way on how to stay the texts in center without manually coding it or something, especially when making an update? I'm making a display for the highest score. Let's say that the score is 9. However, if the score is 9,999,999, the text displays still only at the fixed X and Y coordinate. Is there really a way to stay the text in center especially when there is changes when a player beats the new world record?

Here's my code inside Sprite Batch:

        font.setScale(1.5f);
        font.draw(batch, "HIGHEST SCORE:", (900/10)*1 + 60, (1280/16)*10);
        font.draw(batch, "" + 9999999 + "", (900/10)*4, (1280/16)*8);

        batch.draw(grid_guide, 0, 0, 900, 1280); // --> For testing purpose only.

        // Where 9999999 is a new record score for example.

Here's the image shown as example. I add it some red grid so that I could check if the display of score when updated will always display on center no matter how many digits takes place in. However, it is fixed, so I have to figure it out how to display it automatically on center regardless of the number of digits while updating for the new highscore. I have used the LibGDX preferences very well though to save and load records for the highscore.

enter image description here

© Game Development or respective owner

Related posts about java

Related posts about libgdx