O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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

Putting everything together

We have accomplished our goal of embedding the core Java code in our Cocos2d-x game. Now we are going to show all the parts of our game that have been modified throughout this chapter together.

Here, we show the header file of the C++ JNI bridge (JniBridge.h) that we have created from scratch:

#ifndef __JNI_BRIDGE_H__
#define __JNI_BRIDGE_H__
#include "cocos2d.h"

class JniBridge
{
public:
   static void showToast(const char* message);
};

#endif

Now that we have defined the header of our JniBridge, let us write the implementation file (JniBridge.cpp):

#include "JniBridge.h" #include "platform/android/jni/JniHelper.h" #define CLASS_NAME "com/packtpub/jni/JniFacade" #define METHOD_NAME "showToast" #define PARAM_CODE "(Ljava/lang/String;)V" ...

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