« If iTunes says: "iPhone or iPod detected but not recognized " then... | Main | .NET iPhone development... »

how to optimize the speed of your iPhone game

I use quartz for my 2D game, which does not require many sprites to move, in fact I am staying away from pre-rendered images and use only Quartz shapes, and code in any effects also.

At first it was running really slow on my Touch. But I figured out some tricks to make it run smoother. You have a timer, right, that gets called every fraction of a second. Doing all the gameplay  updates PLUS the rendering (setneedsdisplay function) EVERY time the timer is called makes for slow gameplay and unresponsive touch screen. However, using a counter that gets incremented every time the timer method is called and then reset after it reaches a certain value allows for one iteration to do game physics, one to display, and so on. I split the game physics between two iterations.
I also have a second independent timer that updates less often just to measure the time in the game, otherwise the time would be out of sync with the real time. The reason for that is that calling the NSTimer very often yields inaccurate timing because the time it takes to actually run the method that is called by the timer gets added onto the time between timer calls.

 

So now my game runs almost smooth on the device.

TrackBack

TrackBack URL for this entry:
http://solvengineer.com/blog-mt/mt-tb.fcgi/54/mt-tb.fcgi/55


Hosting by Yahoo!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)