#12. Our score


Hey, today we will look a little on our score screen and his work .  _/

 

At begin i just want to remind you, that every single 4th post on blog related with DSP project is in English (actually except 4th post 😀 )

 


SCORE SCREEN


What is that screen doing? – it’s easy to guess! He displays our score and changes screen!

I had a little troubles with displaying score, I mean I wanted to have special font, size and all i knew was  BitmapFont. Well so i stated to using it but there was a problem, fonts could be only in BMFont file. For me that was a problem because i didnt want to have another ‘fun’ with some extra applications to creating font in that type of file. Then i found that: FreeTypeFontGenerator. Class which can load .ttf files, resizing doesn’t  causes pixels, yeahh that’s it! And …. of course, another problem 🙂  To get that class u need extra libraries, fortunately libGDX ensure good documentation with all that stuff and they predicted that someone will need that. So in libGDX github i found step by step how to install libraries and I have it, I can use it AND IT WORKS!


CODE


That’s my ScoreScreen class, as you can see i’m still using BitmapFont but I’m not creating objects of this class instead of that I’m creating objects of FreeTypeFontGenerator.

 


PROBLEMS?


Yaay, maybe it’s not a problem but …  When we take a look at drawScore() method, we can see many lines like for example

What I’m doing in there? Of course drawing that on screen so we can see result, but that 130, 600 parameters looks awfull. In fact i can create additional variables to keep them in there so everyone knows what that numbers doing but there is so many position’s of x/y axis so code will looks like rubbish bin. If u guys have any idea how to print that in that way with clean code, let me know !

Another problem is variable: 

What is that variable doing? She’s counting how many times screen was touched. Because I have this method

And if i delete screenTouched then, when player finish his game he’s automatically redirect to MenuScreen again, in fact ScoreScreen is displayed but only for a little while like 0.001 sec or smth. I realized that for some reason when I’m redirect to ScoreScreen something is calling Gdx.input.justTouched() once. So I added that screenTouched variable to keep screen on. If u have any ideas how to work around this, let me know 🙂

 


FINAL RESULT 


Here you have example how it’s looks now 🙂


As always feel free to left some comment and hope to see you in next week. BYE 🙂

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *