Skip to content

Instantly share code, notes, and snippets.

@reixa00
Created May 15, 2014 11:53
Show Gist options
  • Save reixa00/c85a8322c70df8a331c2 to your computer and use it in GitHub Desktop.
Save reixa00/c85a8322c70df8a331c2 to your computer and use it in GitHub Desktop.
Calling Android native functions from Cocos2d-x v3.0
package org.cocos2dx.cpp;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import android.util.Log;
public class AppActivity extends Cocos2dxActivity {
public Cocos2dxGLSurfaceView onCreateView() {
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
glSurfaceView.setEGLConfigChooser(5,6,5,0,16,8);
return glSurfaceView;
}
public static void myStaticMethod() {
Log.d("AppActivity", "myStaticMethod()");
}
}
// Imports
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <jni.h>
#include "platform/android/jni/JniHelper.h"
#endif
// Selector
void HelloWorld::SampleSelector()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/cpp/AppActivity", "myStaticMethod", "()V"))
{
CCLOG("[MyScene::init] CallStaticVoidMethod");
t.env->CallStaticVoidMethod(t.classID,t.methodID);
CCLOG("[MyScene::init] CallStaticVoidMethod DONE!");
}
else
{
CCLOG("[MyScene::init] CallStaticVoidMethod CAN'T DO!");
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment