How to call objective C from c++ in cocos2d-x

Hi friends. In this tutorial we will learn to call objective C methods from a c++ class in mac OS
Step 1
Create a new Hello World Project. By default you will have HelloWorldScene.cpp, HelloWorldScene.h, AppDelegate.cpp and AppDelegate.h

Step 2
Now create a new File in your classes folder and name it as ObjCCalls or whatever the name you want.Two more classes will be created in that ObjCCalls.h and ObjCCalls.cpp

Step 3
Now rename the ObjCCalls.cpp class to ObjCCalls.mm.
.mm is an objective c++ class where you can code for both the languages

Step 4
Now in your ObjCCalls.h class write the following

We have made a static method so that we can directly call the method with class name from HelloWorld class
Step 5
In your ObjCCalls.cpp define the static method

Step 6
now in your HelloWorldScene.cpp class, include the ObjCCalls.h class and make a function and define the function as:

So now you are able to call the objective code from a c++ class
HAPPY CODING

3,813 total views, 2 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Leave a Reply