Saving Battery Power in a turn-based game
Now I figured, I could render my game with 1 FPS as long as nothing happens, so I changed my code the following way:
- I start the game with a frameInterval of 60.
- Once I get a “touchesBegan” I go up to 2, that is 30FPS.
- Once I get a “touchesEnded”, I check whether there is any animation going on (the spinning arrows above a selected unit for example) or whether there is still another touch going on. This was pretty straight forward, since I store the points each finger started touching at in a CFDictionary, so I just needed to get its count and check if it’s zero. Then I set the frameInterval to 60 again
- My games main logic-class conforms to a “AnimationResponder” -protocol and the drawing classes store it as a “id<AnimationResponder> delegate”. So once an animation ended, I send this information to the main class and it throttles the FPS back to 1.
The result was so good, I could even feel a difference in the heat of my iPod!
Thank you Ed Welch!