Timer-Based Achievements

One of the most popular achievements in iOS gaming is to play for a certain amount of time. In Whack-a-Cac com.dragonforged.whackacac.play5Mins is used to track the user’s progress towards five minutes of total gameplay. This particular example exists for the loss-of-accuracy problem that was faced in the Whack 1000 example from earlier in this section, and it can be overcome in the same manner.

To track time, a NSTimer will be created. To determine how often the timer should fire, you will need to determine what 1% of five minutes is.

play5MinTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(play5MinTick) userInfo:nil repeats:YES];

When the timer fires a ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.