Cocos2D Embedded In A Cocoa Touch App

On June 12, 2011, in book, cocos2d, by Steffen Itterheim

I just completed this project for the new book chapter about embedding UIKit views/Cocoa Touch in a Cocos2D application. In that case I embedded the Cocos2D view in the View-based Application template and added some controls to start/stop the cocos2d view and change scenes. Here’s the result:

It also correctly auto-rotates. But I noticed an odd bug with auto-rotation enabled for all orientations: the view is designed in portrait mode. If I start the App on my iPod Touch 4 while holding the device in landscape mode, then rotate back to portrait mode once the app has started and enable the cocos2d view, for some reason this causes my device to reboot! I see a transparent white color drawn over the entire screen before the screen goes black and the Apple logo appears.

If anyone has any idea what might be causing this behavior, please let me know. As far as I debugged it is not the initialization of the EAGLView class itself, a scene is already running or about to be run.

I’m guessing it might have to do with the EAGLView initialization, since I rely on Interface Builder to initialize the view. I simply dragged a View object onto IB and changed the class from UIView to EAGLView. Maybe the EAGLView default settings are not supposed to be used and I do need to create the EAGLView manually?

Tagged with:  

Cocos2D with a Touch of Cocoa

On May 31, 2011, in book, cocos2d, by Steffen Itterheim

When I asked on Twitter what kind of chapter you’d like to see in , I got some great responses! The most votes were for more complex physics examples, all other suggestions were all over the place. Saving and loading, optimizations and organizing bigger games, audio programming and Cocos3D. I think they would all deserve a chapter of their own, and in fact I’ll get you started with ObjectAL and Cocos3D in the chapter about Kobold2D.

But after some research I realized that one of the most frequent issues with an apparent lack in good answers are about integrating Cocoa Touch (UIKit) in a Cocos2D application. Or vice versa, adding Cocos2D to a Cocoa Touch application. There are many things to consider, and it’s easy to run into problems. This topic is especially persistant because on the one hand there are a lot of Cocoa Touch programmers who are starting to use Cocos2D, whereas there are also many Cocos2D users who know little of Cocoa Touch – and both want to use the best of both worlds.

Here’s a preliminary list of topics I’d like to get into:

  • RootViewController explained
  • Cocoa Touch views in a Cocos2D app (eg In-App Mail)
  • Starting & stopping Cocos2D in a Cocoa Touch app
  • Properly handling autorotation
  • Performance considerations
  • Adding iAd banners

If you have a suggestion that is not on this list feel free to add it in a comment!

Tagged with: