dance to the beat

In this version I added a fixed time step to the display link update callback. I noticed very small increases and decreases in the movement rate of the green meanies, so by fixing the update to a fixed time step, it appeared to help a bit. This is also a useful technique for ensuring repeatable time-based physics in different replays of a game/simulation, so it was a good point to add this in.

I also fixed a black flickering on the bottom row of the map; the layout of tiles was done in the touch event callback, instead of the display link callback, so I added a _needsLayout flag which is used to layout the tiles in a frame.

In a similar manner, I also added a _needsTransform flag. This is used to reduce the number of core animation calls, so that the scrolling animation only happens when it needs to, and not once every frame.

With these optimisations, I’m getting anywhere from 30 to 40 frames per second (FPS) during scrolling on an iPod 4th generation device, a slightly better frame rate on an iPad 1st generation, and the iPod 5th generation has been getting 60 FPS since the first prototype. This is all pretty good considering it’s all just Objective-C and I’m not using OpenGL ES.

For more information, see the gaffer on games article fix your time step!