scale scoring text

Hello,

I guess this is newbie question.

I have a text object displaying some score, it occupies a defined portion of the screen. Obviously the score would get bigger when determined events occur, so how should I approach a method to scale the size of the size of the text once the score value reaches a certain value, say 100, and then again once it gets 1000, and so forth???

Thank you…

Hi @akak,

Have you tried just re-setting the size of the text object?

http://docs.coronalabs.com/api/type/TextObject/size.html

Another option may be to begin the text at the largest size, then scale it down initially (to retain a nice crisp look). Then later in the game, you could transition scale it back upward to achieve a smooth animation effect, instead of just outright jumping up in size.

Brent

Hi Brent,

as far as the graphical output I thought as well of using scale() the text object. My problem regards creating a function that handles scaling up and down according to the current score. I have trouble figuring out how to size it back to normal when the score decreases:

local function checkTotal ()   if not firstCheck then --- this is to prevent from keep the scaling past 99      if Total \> 99 then ----Total is the current score (as of now is incremented by one each time)         sumTotal:scale(.7, .7) ----- sumTotal is the text object that displays the score         firstCheck = true      end   end   print ("checking") end Runtime:addEventListener( "enterFrame", checkTotal ) ---- This is temporary, but I need a runtime event to check on the score.

As you can see I miss the logic to scale back if score goes back below 100.

Could do something like this:

[lua]

local function checkTotal ()

      local scales = {{ 100 , 0.7 },{ 1000 , 0.8 },{ 10000 , 0.9 },{ 100000 , 1 }}    – setup a table of score thresholds

      sumTotal:scale( .5 , .5 )        – scale value for score below first threshold

      for i = 1 , #scales, 1 do      – loop through the table of score thresholds

            if Total >= scales[i][1] then – if score meets this threshold

           

                  sumTotal:scale(scales[i][2], scales[i][2]) ----- re-scale according to the table

            end

      end

end

Runtime:addEventListener( “enterFrame”, checkTotal )  ---- This is temporary, but I need a runtime event to check on the score.

[/lua]

Thanks Nick,

That’s clever! I’m new to programming and not yet comfortable with using tables associated with for loops. I see how your thing is working though and that’s the solution I was trying to figure out.

How would you handle the case of negative numbers? Would you set up a ‘twin’ table like “scale2” containing negative numbers assiocated with same scaling factors as:

local scales2 = {{ - 100, 0.7},{ - 1000, 0.8},{ - 10000,0.9},{ - 100000,1}}

on my own so far I only had managed to come up with this:

local function checkTotal () &nbsp; if not firstCheck then &nbsp;&nbsp;&nbsp;&nbsp; if Total \> 99 or Total \< - 99 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal:scale(.5, .5) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstCheck = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; checkBack = true &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp; end&nbsp; &nbsp; &nbsp; if checkBack then &nbsp;&nbsp;&nbsp;&nbsp; if Total \< 99 and Total \> - 99 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal:scale(2, 2) &nbsp;&nbsp;&nbsp;&nbsp; firstCheck = false &nbsp;&nbsp;&nbsp;&nbsp; checkBack&nbsp; = false &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp; end

Considered the portion of screen I can allocate for the score text, this manages to handle the issue up to + and - tens of thousands.

Which is more than acceptable in my case.

But this raise another question for me as to how to sistematically proceed in case of infinite values.

For example I want ot create a simple counter application also using that scaling method for the graphic output of the value we are counting on.

Realistically such an app would be used to count up to tens (like sports score tallying) or hundreds at max, but theoretically there shouldn’t be a number limit.

So how do you expert developpers usually approach this kind of circumstance? You settle with, like in this case, leaving space for a ample but finite margin of ‘maneuver’ or you force yourself to prevent every single ‘paradox’ in your project (i.e. even if it’s very unlikely you’d put in a method to handle the case my user decides to count up to 100.000) ???

Thanks for the attention…

To include negative numbers, just use math.abs(Total) > 99 - it will then treat -99 the same as +99.

As for your other question, I guess you might impose some sort of limit but you wouldn’t have to. There would be a point where If the number got so big (i.e. 100,000,000) you could start to scale it down so it fits on screen.

Hi @akak,

Have you tried just re-setting the size of the text object?

http://docs.coronalabs.com/api/type/TextObject/size.html

Another option may be to begin the text at the largest size, then scale it down initially (to retain a nice crisp look). Then later in the game, you could transition scale it back upward to achieve a smooth animation effect, instead of just outright jumping up in size.

Brent

Hi Brent,

as far as the graphical output I thought as well of using scale() the text object. My problem regards creating a function that handles scaling up and down according to the current score. I have trouble figuring out how to size it back to normal when the score decreases:

local function checkTotal () &nbsp; if not firstCheck then --- this is to prevent from keep the scaling past 99 &nbsp;&nbsp;&nbsp;&nbsp; if Total \> 99 then ----Total is the current score (as of now is incremented by one each time) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal:scale(.7, .7) ----- sumTotal is the text object that displays the score &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstCheck = true &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp; end &nbsp; print ("checking") end Runtime:addEventListener( "enterFrame", checkTotal ) ---- This is temporary, but I need a runtime event to check on the score.

As you can see I miss the logic to scale back if score goes back below 100.

Could do something like this:

[lua]

local function checkTotal ()

      local scales = {{ 100 , 0.7 },{ 1000 , 0.8 },{ 10000 , 0.9 },{ 100000 , 1 }}    – setup a table of score thresholds

      sumTotal:scale( .5 , .5 )        – scale value for score below first threshold

      for i = 1 , #scales, 1 do      – loop through the table of score thresholds

            if Total >= scales[i][1] then – if score meets this threshold

           

                  sumTotal:scale(scales[i][2], scales[i][2]) ----- re-scale according to the table

            end

      end

end

Runtime:addEventListener( “enterFrame”, checkTotal )  ---- This is temporary, but I need a runtime event to check on the score.

[/lua]

Thanks Nick,

That’s clever! I’m new to programming and not yet comfortable with using tables associated with for loops. I see how your thing is working though and that’s the solution I was trying to figure out.

How would you handle the case of negative numbers? Would you set up a ‘twin’ table like “scale2” containing negative numbers assiocated with same scaling factors as:

local scales2 = {{ - 100, 0.7},{ - 1000, 0.8},{ - 10000,0.9},{ - 100000,1}}

on my own so far I only had managed to come up with this:

local function checkTotal () &nbsp; if not firstCheck then &nbsp;&nbsp;&nbsp;&nbsp; if Total \> 99 or Total \< - 99 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal:scale(.5, .5) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstCheck = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; checkBack = true &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp; end&nbsp; &nbsp; &nbsp; if checkBack then &nbsp;&nbsp;&nbsp;&nbsp; if Total \< 99 and Total \> - 99 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal:scale(2, 2) &nbsp;&nbsp;&nbsp;&nbsp; firstCheck = false &nbsp;&nbsp;&nbsp;&nbsp; checkBack&nbsp; = false &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp; end

Considered the portion of screen I can allocate for the score text, this manages to handle the issue up to + and - tens of thousands.

Which is more than acceptable in my case.

But this raise another question for me as to how to sistematically proceed in case of infinite values.

For example I want ot create a simple counter application also using that scaling method for the graphic output of the value we are counting on.

Realistically such an app would be used to count up to tens (like sports score tallying) or hundreds at max, but theoretically there shouldn’t be a number limit.

So how do you expert developpers usually approach this kind of circumstance? You settle with, like in this case, leaving space for a ample but finite margin of ‘maneuver’ or you force yourself to prevent every single ‘paradox’ in your project (i.e. even if it’s very unlikely you’d put in a method to handle the case my user decides to count up to 100.000) ???

Thanks for the attention…

To include negative numbers, just use math.abs(Total) > 99 - it will then treat -99 the same as +99.

As for your other question, I guess you might impose some sort of limit but you wouldn’t have to. There would be a point where If the number got so big (i.e. 100,000,000) you could start to scale it down so it fits on screen.