Changing Game Score to Font Images AND centering

j75j75 Member, PRO Posts: 235
edited January 2014 in Working with GS (Mac)
I have a game set up that has space for 10 score numbers allocated.
The numbers are constrained to images so that the score is displayed in a custom font as directed by a tshirtbooth video.

Since I have so many numbers for the score, I have added a feature that makes the score digits transparent if it is not in use.

So, instead of...
00000001525
it will delete the "0's" that are not in use, like so.
..............1525

My question is, is there a way to have the visible score numbers centered to the screen?
As it sits now, the score starts from the right and continues left as is grows.

Thanks!

Comments

  • j75j75 Member, PRO Posts: 235
    edited January 2014
    I'm thinking maybe there is a different way to display the score that will add digits as necessary and stay centered. ???
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    With custom fonts, you are using one actor for each digit. The only way to center the actors is to use mathematical formulas for their self.Position.X values. You'd have to work out the math for that unless someone else here can help you out.

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

  • 3itg3itg Member, PRO Posts: 382
    lets just say that every number is 40px...
    you will do this on every actor in the score.
    you have an actor for each place, like zero, ten, hundred, thousand
    and they all start off in the same spot.

    for the zero place actor:
    if game.score is > or = to 10
    Position.X + 20
    if game.score is > or = to 100
    Position.X +40
    if game.score is > or = to 1000
    position.X + 60


    for the other actors:
    if game.score is > or = to 10
    Position.X - 20
    if game.score is > or = to 100
    Position.X - 40
    if game.score is > or = to 1000
    Position.X - 60

    this is off the top of my head, I didn't check it in GS so I may have forgot something...
    Also, the actor I used spawned the other numbers, so you probably will have to tweak this a little bit.
  • j75j75 Member, PRO Posts: 235
    Thanks guys.
    I will play around with the positions and try to make it work.
  • jigglybeanjigglybean Member Posts: 1,584
    Probably the easiest way I have found

    Like Balls? Then click here! We've 100 coming soon

  • ArmellineArmelline Member, PRO Posts: 5,371
    edited January 2014
    I had to solve this problem for my game Snowflakes. The solution I came up with wasn't hugely elegant, but it worked. I was going to make a template for it but it totally slipped my mind. The solution I used was along the lines found in this thread.

    For growing numbers to the left, it's as simple as using alpha values to hide the 0s until they're in use.

    For growing numbers to the right, tatiang came up with a formula that was more elegant than anything I'd come up with, but I don't think I went back and changed my code. Should probably do that. I'll see if I can dig up the thread we discussed it in.

    For keeping centred, it's much more fiddly but really not very complicated. I complicated things slightly more by needing to put a + or - at the start of the number.

    I'll PM you a link to a quick and dirty example of how I chose to do it. Please note though that it can be tightened up a lot. I was finishing this game in a mad rush to get it released by Christmas and in time for the Amazon promotion. Although the end user experience was what I was after, the code behind it wasn't as carefully optimised as I like. I also had a reason for using individual actors for each digit, but I expect the same result could be achieved with one actor and a bunch of extra if statements.

    If I get time I'll comment and organise the code and add example buttons and things to make a real template, but what I'm sending you is the best I can manage for now, and shows you everything you need to know to translate it to your game and cut down the code a fair bit!
  • ArmellineArmelline Member, PRO Posts: 5,371
    Oh, one more thing. The example I sent you tracks scores of up to 9,999,999. Due to the legwork needed (at least using my rather inelegant method) to move the scores, each extra digit you add is a bunch of extra work and effort. So for 10 digits you'll be looking at a fair bit of fiddling :P I'd strongly recommend you look at how I achieved the result I did and use it as inspiration rather than trying to directly copy the rules. A few minor changes would cut down the effort needed to add digits by a lot.
Sign In or Register to comment.