We have an iOS application (which is built with Objective-C). Now we want to build some game inside the app and we would like to use Cocos2d-X. Therefore, we need to find a way to embed / integrate Cocos2d-x into our Xcode project. The reason we choose Cocos2d-X is we need to build those games on Android as well.
PS: I found some tips do that but they are very old now.
Thanks !
UPDATE:
I resolved this by myself. This issue should be closed !
Hello ngoclt,
We have the same question to embed / integrate Cocos2d-x into an iOS project. We work for the question for a week, but still failed with some error. Can you help me?
Thanks!
PS:My email 344748930@qq.com
3, Try to build projects, there should be some Error that inform you that can’t find some Frameworks. You will need to add those frameworks to your project.
4, Change the extension of AppDelegate implementation file to .mm (that allows your code support Objective-C++)
Add this code to AppDelegate.mm
And this, (that notify your game controller - will show u below - when app is put into background or back to foreground):
5, Define your game controller (a view that will display your game):
I’m trying to do the same on OS X but the AppDelegate is quite different in Cocos2d-x v3.10, would you mind sharing your thoughts on how to accomplish this on a mac application?
I’m really sorry since I can’t access to that project anymore since it was a project in my previous company. I’m working on a sample project which will embed latest cocos2dx version into an iOS application. Hopefully, I will be able to finish it by tomorrow.
Really sorry for couldn’t keep following on this topic. Anyway, I actually created an example project for doing this last year. But just couldn’t finish it and share with you guys. Here is what I have been done so far: https://github.com/ngoclt/iOSCocos2dXApp
There is only one issue left which is the app will crash after you open the game again. You will need to call the method to end game from C++, here is the code:
void BaseLayer::backToApp(Ref *sender)
{
// This is the method to call a method in Objective-C (I used EasyNDK lib)
sendMessageWithParams("backToApp", Value::Null);
Director::getInstance()->end();
}
Method backToApp is implemented in GameController.