Cocos2d + UIKit
I haven't been writing much in here because I've been busy programming our new Hopscotch iOS app. This is a little bit of a PSA to save others from the giant gotcha I encountered when integrating Cocos2d into my UIKit app to power user-generated animations.
First, I used the excellent Kobold2d library to install cocos2d by following this tutorial. (This involved starting a new Xcode project and copying over my old files, amazing that this was far and away better than any alternative solution I encountered). Here's where a whole new set of problems kicked int: my app became incredibly slow. It was difficult to pinpoint the problem since so many things had to change in order to integrate this library.
My original code to integrate cocos2d looked something like this:
https://gist.github.com/3661164
After several weeks of forging ahead and continually wondering why my app was so crashy and slow I finally sat down to solve the problem. I used Apple's Instruments application with the core animation template (NB: this only works on your device, not the simulator). When I checked "Flash Updated Regions" it quickly became clear what was wrong: my (mostly) offscreen stage view where animations would render was updating 60 times per second, even when all animations were stopped.
Armed with this knowledge the solution was simple. I set the frame right down to 10 seconds and only increased it when an animation was actually running. I added code to the reveal and conceal functions to make sure the frame right was always appropriate and my app was back to its old responsive self:
https://gist.github.com/3661121
















