Custom Fonts For Score System!! - tutorial

DanDaMan123DanDaMan123 Member Posts: 216
edited August 2012 in Community Tutorials
Hi so I have been working on a game and I decided to make minigames. I want my game to be very high-end so I tried to find the most efficient way to do custom fonts for a scoring system. This uses only ONE behavior per digit and no tables at all. Also a single score attribute.

For the numbers I have ten custom images, 0-9, names corresponding to their number.

So I used three actor instances to get a three digit numbering system, one for the one's digit, one for ten's, and hundred's. I also have an attribute for the score. In the ones digit actor I created a behavior that said:

constrain attribute > self.image - to - game.score%10

The % creates sort of a cycle thing. I can't explain it very well but one example of it is angles/rotation. If something is 359 degrees, and you increase it 5 degrees, it doesn't become 364 degrees, the cycle starts over and it becomes 4 degrees. Also with time. An hour past 12:30 isn't 13:30, it's 1:30. So, when I do %10, it makes the number cycle around 10, staying single digit, which is what we want.

For the tens and hundreds, it's similar, but we have to add a little more.

Because we want to manipulate the tens digits to revolve around the single digits 0-9 we must divide by ten. But, if the score was something like 17 for example that would leave us with 1.7, which just throws us off. So, we round down with the floor function. In the end, for the ten's we get this:

constrain attribute > self.image - to - floor( game.score/10 ) % 10

Then for the hundreds it's almost the same:

constrain attribute > self.image - to - floor( game.score/100 ) % 10
(notice the 100 rather then 10)

I hope that this helps many people and if anyone knows a better way please tell us all!


  • arcticsunrisearcticsunrise Member Posts: 159
    yup this is similar to the formula DBApps use for their AgroBirds template/game.

    So ven better optimised is one actor and you set a custom attribute on the actor called divisible and then in the equation you have

    floor(( game.playerScore % self.Divisible )/( self.Divisible /10))..".png"

    thats for the first one then all you do is in the scene (not prototype) you copy the actor and change the self.Divisible to 100 or 1000 or 10000 to get each of the numbers.

    even more efficient i think !

    even more efficient is unless you are showing the score going up in realtime on your game is to not use constrain attribute as this east up system resources - so if you are only showing score at the end of a level for example use a boolean trigger and have it as change attribute and not constrain.

  • DanDaMan123DanDaMan123 Member Posts: 216
    that works too!
  • dominiconlinedominiconline Member Posts: 5
    both of these don't work for me, its driving me insane, i follow the tutorial to the letter nothing...
  • DanDaMan123DanDaMan123 Member Posts: 216
    do you have images named "1" "2" "3" etc.?
Sign In or Register to comment.