Migrating to cocos2d-iphone v3 - Tips & Tricks
This is a collection of Tips & Tricks for users who are migrating to cocos2d-iphone v3 from v2. Mostly refers to questions posted on stackoverflow.com.
Please excuse the short, bullet-pointed format. I’m a little short on time but didn’t want to miss out on another biweekly post like I did two weeks ago (first time in about 4 years, ouch).
General Tips
- Many classes have been renamed…
“Use the source, Luke!” If you don’t find what you are looking for:
- Check the cocos2d API class reference
- Start typing the class or method name, see what suggestions Xcode autocomplete has for you
- Use part of the class name (ie “repeatforever”) and perform a “Find in Project” to search through all source code files
- Tutorial XYZ won’t work with v3!
Yes, it won’t. Most likely it was written for cocos2d-iphone v2.
Question is: do you have to use v3? And do you have to use it right now?
Because if you’re in the process of learning cocos2d it’ll be easier to learn from and with v2 tutorials/books for the time being until more v3 tutorials have been published.
- How to upgrade an existing cocos2d v2 project to v3?
How to display NSView on top of cocos2d-iphone’s OpenGL view on Mac OS X
Everyone knows how to add a UIView to an iOS app built with cocos2d-iphone. It’s straightforward, just create the view and then call:
1 |
[[CCDirector sharedDirector].view addSubview:theView]; |
There. Now suppose you want to do the same on Mac OS X. HA! HA! Hawww!
Cocoa’s laughing at your feeble attempts. It’s really just Cocoa’s fault though. Having done a fair amount of work with both SDKs, the Cocoa on OS X just feels … old. Backwards. Confuscated. No, not confusing, literally confuscated - it can’t even spell confusing like everyone else does.
But … there is always a way. On OS X it’s just more often than on iOS a matter of finding the right way. It can be done. Here’s proof:
The Right Way™
The trick here is to create an additional “overlay” NSWindow that’ll hold all of your views. Actually, it’s not the overlay window it’s the overlay window’s content view, which is just an empty NSView. But first things first, step by step. Continue reading »
Scheduled for release on November 7th, 2011. Continue reading »