Created
May 15, 2014 11:53
-
-
Save reixa00/c85a8322c70df8a331c2 to your computer and use it in GitHub Desktop.
Calling Android native functions from Cocos2d-x v3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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