O'Reilly logo

Cocos2d-x Cookbook by Akihiro Matsuura

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using native code

In Cocos2d-x, you can write one source for the cross platform. However, you have to write an Objective-C function or a Java function for the dependency process such as a purchase or push notification. If you want to call Java for Android from C++, you have to use JNI (Java Native Interface). In particular, JNI is very confusing. To call Java from C++, you have to use JNI. In this recipe, we will explain how to call an Objective-C function or a Java function from C++.

Getting ready

In this case, we will make a new class called Platform. You can get the application version by using this class. Before writing code, you will make three files called Platform.h, Platform.mm, and Platform.cpp in your project.

It is important that you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required