Custom font scorekeeping with negative numbers and rightward expansion

ArmellineArmelline Member, PRO Posts: 5,327
edited December 2013 in Working with GS (Mac)
Wondering if there's any interest in me breaking this off and making it into a template. I ask because I did some fairly extensive searching before trying to solve the first problem and moderate searching before trying to solve the second. Neither yielded any helpful results.

So the game I'm polishing up at the moment deals in fairly large scores, which can go heavily into the negative too. It was essential I use a custom font. My starting point was tshirtbooth's custom font scoring tutorial. This is a great start but has two big limitations:

1. It cannot handle negative numbers.

This was a big issue for me. The game I'm making is fairly punishing - if you aren't fast enough you'll end up with a negative score. Perhaps even a pretty big one. tshirtbooth's method is great for positive numbers but couldn't handle negative ones. I expect there is a better and more elegant solution, but the solution I came up with was to use abs() to invert the negative score into a positive one and use that number to power the scorekeeping when the score dipped into negatives. A simple +/- at the start of the score shows if it's positive or negative.

2. You need to pre-place all the possible numbers.

Let's say you want to track a score with a possible upper limit of 999. That means placing three actors - 000 - and updating each one as the score changes. Adding 1 gives you 001, adding 65 gives 065, adding 156 gives 156 etc. This is great when scores are smallish, and I opted to use this method in a previous game because it just looked better. For the game I'm finishing up at the moment, though, the scores get big. Into the millions, theoretically. So I'd end up with 0000000 when a player started. Not pretty. Instead, I'm growing the score to the right, so if the user has a score of 1243 they see 1243, not 0001243. If they have 10, they see 10, not 0000010. If their score drops, the numbers shift back to the left.

I'm starting to ramble, so I'll cut to the chase. Would anyone be interested in a template for this kind of score keeping Alternatively, can anyone point me at a template that does the same things so I can compare their method to mine, and see if I can optimise mine? :D

I'm not sure if I'll have time in the immediate future to make such a template, but if there's interest it'll motivate me to at least try :D

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    To solve the problem of too many leading zeros, you need to add a rule to each actor that says When [my value] = 0, change self.color.alpha to 0; Otherwise change self.color.alpha to 1. And the positive/negative issue also has a simple solution, as you discovered.

    Edit: see my post below.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,327
    edited December 2013
    Here's some:

    http://www.stormystudio.com/game_templates/hearts_score.html

    This example doesn't seem to really address either issue outlined above. I guess I didn't explain very clearly as neither response so far actually seem to have understood the main problem I set out to solve :(
    To solve the problem of too many leading zeros, you need to add a rule to each actor that says When [my value] = 0, change self.color.alpha to 0; Otherwise change self.color.alpha to 1. And the positive/negative issue also has a simple solution, as you discovered.
    This only solves the problem if your score is aligned to the right of the screen. In my situation I wanted to say:

    Score: 1

    but also

    Score: 135324563

    Making the leading 0s invisible leads to odd results in this situation. I'm not offering a template solving a problem quite so simple.

    There doesn't seem to be any interest in a template though, so it's all kinda moot :D
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Sorry, my response was a little off. Only display the digit actor if the total value of the number is greater than that digit's place. For example, if you have the score 1050, then the hundreds digit would be visible because 1050>999. But the ten thousands digit would be invisible because 1050<9999.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,327
    edited December 2013
    Sorry, my response was a little off. Only display the digit actor if the total value of the number is greater than that digit's place. For example, if you have the score 1050, then the hundreds digit would be visible because 1050>999. But the ten thousands digit would be invisible because 1050<9999.</blockquote>

    I've had a very long and tiring day so this may just be me being slow, but how would this solve the issue of shifting to the right/left? Not displaying the thousands when the score is only in the hundreds would still leave that blank space before the score number.

    What I mean is something like this:

    image

    Unless I'm being particularly slow tonight, this effect can't be achieved by just hiding and showing the digits. I really thought I made it very clear in my first post :(
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    No, it's probably that I'm not picturing your setup correctly. :-?

    Ah, okay, I just go it. In that case you'd have to do some fancy footwork by moving the actors to a certain position based on the value of the score. You're right, that is kind of a pain.

    I added a rule to this demo (not mine) to show you what I mean, but this doesn't take into account my Aha! moment above.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,327
    edited December 2013

    Ah, okay, I just go it. In that case you'd have to do some fancy footwork by moving the actors to a certain position based on the value of the score. You're right, that is kind of a pain.
    This is exactly what I did and was offering to share with the community :P I did think there was some value to the template, else I'd not have offered to make it :P

    I added a rule to this demo (not mine) to show you what I mean, but this doesn't take into account my Aha! moment above.
    This is almost what I mean, but my example expands the numbers to the right, not the left. (As you now realise.) Expanding to the left is super-simple, expanding them to the right took a bit more thought and effort :P The .gif I added hopefully illustrates things better.

    What I offered in my original post was a template that takes custom fonts for scores and adds two benefits: Working negative numbers, and expansion to the right (and back to the left when the number decreases again).
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I think I have a good solution for the left/right problem. Stay tuned!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Then....... yes, the template sounds valuable! lol... sorry, it's Monday for me, too. :)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,327
    Then....... yes, the template sounds valuable! lol... sorry, it's Monday for me, too. :)
    Today is definitely one of those days :D I just got my Pro membership through and need to get some apps published on the App Store at last and yet I can barely string together a coherent thought...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, I don't know if this is similar to what you came up with, but here's my solution (see attached file for demo). Note that 176 is the x position of the leftmost digit (where the score digits should begin displaying on the scene).

    Constrain self.position.X to:
    image

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,327
    It is very similar and at the same time totally different :D It was important to me that I could whack a score down anywhere and have it work without needing to edit formulas. The core idea was the same, but some differences cascaded from there. Your solution is actually more elegant, though.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If I were going to automate it to avoid the need for a constant (176), I would have the first digit actor that I place down spawn the remaining digits and have each digit grab its divisor from a game attribute that changes during the spawning loop. Each digit would also grab the constant (e.g. 176) from the first digit's self.position.X. A bit of work so I don't know that I'll be doing that now but it's an intriguing idea.

    Would love to see your method when you have the time to post it.

    Have a good one!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.