You often hear that C++ is preferable to Objective-C for games, especially in a resource-constrained environment like the iPhone. (I know you still need some Objective-C to initially talk to iPhone services.) Yet, the 2D game engine of choice these days seems to be Cocos2d, which is Objective-C.
I understand that what Apple calls “Objective-C++” allows you to mix C++ and Objective-C classes in a single file, but you can’t mix and match the languages’ constructs within the same class or function.
So, is it sensible/possible to use Cocos2d for a C++ game? Do you have to write a lot of “glue” code? I’d like to avoid some of the heavy lifting that a direct OpenGL-ES approach would require.
I’m currently prototyping a game with Cocos2. I’m writing the game logic in C++ with Chipmunk and then using Cocos to implement the view layer. You can indeed mix C++ and Objective-C freely in the same class, function and line of code. I’m sure there are limits, like you probably can’t mix Objective-C and C++ method definition syntax in a class interface (I actually hadn’t thought to try), but for most practical purposes you can mix freely.
If you are only targeting iPhone then I wouldn’t be too worried about writing everything in Objective-C. As others have mentioned, if anything is actually a performance bottleneck you can just profile and optimize it. I am writing my game core in C++ because I may want to deploy on other platforms and in that case Objective-C will become a liability.