game currency convert: math efficient
Posted
by
Comradsky
on Stack Overflow
See other posts from Stack Overflow
or by Comradsky
Published on 2012-09-15T16:17:34Z
Indexed on
2012/09/17
21:38 UTC
Read the original article
Hit count: 170
For variables:4 text views named diamondText
, goldText
, silverText
, and bronzeText
;money variable unsigned int money
;and an NSTimer
, every .1 sec,runs function:
-(void)updateMoney{
money++;
bronzeText.text = [NSString stringWithFormat:@"%d",money];
silverText.text = [NSString stringWithFormat:@"%d",money%10];
goldText.text = [NSString stringWithFormat:@"%d",money%100];
diamondText.text= [NSString stringWithFormat:@"%d",money%1000];
}
Given that my currency is diamond = 10 gold = 10 silver = 10 bronze = 1;
What would be most efficient way to calculate and display the money labels? How would you store this variable, with GameCenter and NSDictionary or GameCenter and something else?
More details are below if you don't understand.
To clarify: bronze has the last 2 numbers, silver has the next 2 numbers, and so on.
I understand I could use 4 ints or an array, but i would rather try to use this method, unless theres a much more efficient way.
Example: When money = 1000
;bronzeText = nothing
, silverText = 10
,goldText = nothing
, diamondText = nothing
;
What other ways would you do this that you think would be more efficient? I will be calling a function (void)collisionDetector
that detects if my player.frame
crosses with a flyingObject.frame
, and if that object is a coin it gives an added value to money and then calls (void)updateMoney
. Im just using the timer to test this and spawn these flying objects.
© Stack Overflow or respective owner