Skip to content

Instantly share code, notes, and snippets.

@talentless
Created November 2, 2011 15:48
Show Gist options
  • Save talentless/1333988 to your computer and use it in GitHub Desktop.
Save talentless/1333988 to your computer and use it in GitHub Desktop.
-(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