Created
November 2, 2011 15:48
-
-
Save talentless/1333988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) update_:(ccTime)dt { | |
int direction = 1; // the score can roll in either direction | |
if (self.score < curScore_) { | |
direction = -1; | |
} | |
double pointChange = self.pointsPerSecond * direction * dt; | |
curScore_ += pointChange; | |
// don't let it overrun the target | |
if (direction == -1 && curScore_ < self.score) { | |
curScore_ = self.score; | |
} else if (direction == 1 && curScore_ > self.score) { | |
curScore_ = self.score; | |
} | |
// update the string | |
// this is as costly as creating a new label | |
// we should be using cclabelatlas | |
[self setString:[NSString stringWithFormat:self.formatString, (int)curScore_]]; | |
// if we are at the score then stop updating | |
if (self.score == curScore_) { | |
[self unschedule:@selector(update_:)]; | |
updating_ = FALSE; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment