我想访问 jni main.cpp 中的场景,但是当我调用 cocos2d::CCDirector::sharedDirector()->getRunningScene()
时我无法获取它!
我的代码:
void Java_tehrannama_test_tehrannama2_zoomIn(JNIEnv* env, jobject thiz,jfloat s) {
__android_log_print(ANDROID_LOG_DEBUG, "zoom1", "zooom");
HelloWorld* helloworld = dynamic_cast<HelloWorld*>(cocos2d::CCDirector::sharedDirector()->getRunningScene());
helloworld->zoomin(s);
helloworld->center.x = helloworld->center.x -10000;
}
除了 helloworld,我没有其他场景。
最佳答案
我发现这个问题实际上是我的错误!我的 helloworld 图层作为当前场景的子级添加,解决方案是在添加时标记 helloworld,然后获取它,如下所示:
HelloWorld* helloworld = dynamic_cast<HelloWorld*>(cocos2d::CCDirector::sharedDirector()->getRunningScene()->getChildByTag(1));
关于android-ndk - 访问jni main.cpp中的运行场景(cocos2d-x),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10419030/