Archive for Power Saving

Saving Battery Power in a turn-based game

Posted in Uncategorized with tags , , , , , on August 2, 2010 by bersaelor

I got inspired by a post on the toucharcade-forums by ed_welch who describes how he throttles FPS manually to the minimum value any animation needs to run.

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!

Advertisements