samedi 28 février 2015

How to replace cocos2d-x scene from Java?



I want to replace the scene in a cocos2d project from Java. I created the following JNI methods:



void cocos_android_app_init (JNIEnv* env, jobject thiz) {
LOGD("cocos_android_app_init");
AppDelegate *pAppDelegate = new AppDelegate();
}

extern "C" {
JNIEXPORT void JNICALL Java_com_example_myapp_MainActivity_changeScene(
JNIEnv* env, jobject thiz){
cocos2d::Scene* scene = MyScene::createScene();
Director::getInstance()->replaceScene(
TransitionFade::create( 1, scene ));
//NOT WORKING BECAUSE Director::getInstance() is NULL
}
}


However, when the method changeScene is called from java, my App crashes because Director::getInstance() seems to be a NULL-pointer. How can the scene be changed correctly from Java?




Aucun commentaire:

Enregistrer un commentaire