cocos2d-x 위키 샘플보면
// SampleNative.h
#ifdef __cplusplus
extern "C" {
#endif
jint Java_org_cocos2dx_sample_Sample_nativeAdd(JNIEnv *env, jobject thiz, jint a, jint b)
{
return a + b;
}
#ifdef __cplusplus
}
#endif
jni c++호출은 이렇게 사용하는데요; 만약에 이부분을
jint Java_org_cocos2dx_sample_Sample_nativeAdd(JNIEnv *env, jobject thiz, jint a, jint b)
{
CCDirector* pDirector = CCDirector::sharedDirector();
CCScene* pScene = pDirector->getRunningScene();
int tag = pScene->getTag();
return (jint)tag;
}
#ifdef __cplusplus
}
#endif
이런식으로 cocos2d-x의 게임 코드와 연동하고싶은데 안되네요ㅠㅠ
cocos2d-x <-> Android api 사이의 호출이 잦은 앱을 만드려고 하는데... 잘 안되네요..
어떻게 하면 두 라이브러리 간에 연동이 될까요??
#include "AppDelegate.h"
#include <JniHelper.h>
#include <jni.h>
using namespace cocos2d;
using namespace cocos2d::extension;
#ifndef __jnitest
extern "C" {
#endif
jint Java_com_swm_vg_testgame_JNIVoiceRecogTest_cppFunctionTest(JNIEnv* env, jobject thisObj, jint a, jint b)
{
CCDirector* pDirector = CCDirector::sharedDirector();
CCScene* pScene = pDirector->getRunningScene();
int tag = pScene->getTag();
return (jint)tag;
}
#ifndef __jnitest
}
#endif
이렇게 해서 컴파일 성공하고.
자바에서는 핸들러로 몇초 딜레이준뒤 테스트해보니 라이프사이클 이후에 되서 해결했네요~
며칠삽질한게 이렇게간단하다니..ㅠㅠ
jni 연동도 연동이지만. cocos2d 엔진이 로딩되어서 화면에 그리기까지 라이프 사이클이 있습니다.
hello world 샘플을 보고 그부분을 확인해 보세요..