android-ndk - 访问jni main.cpp中的运行场景(cocos2d-x)

标签 android-ndk cocos2d-x

我想访问 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/

相关文章:

ios - cocos 2d x捕获屏幕截图并在ios c++中立即显示

安卓 : NDK : Superpowered Open failed: ENOENT (No such file or directory) Error

java - Android (ART) 崩溃并出现错误 JNI DETECTED ERROR IN APPLICATION : jstring is an invalid local reference

c++ - 带有静态库 : linker throws 'undefined reference' all the time 的 Android NDK

android - 只为 android apk 保留 armeabi-v7a 是否安全

android - cocos2dx- 3.7 和 3.7.1 cocos studio 不工作

box2d - 如何在box2d和cocos2dx中创建像蛇一样的 body ?

iphone - 格式与字符串 : Cocos2d-x passing in a CCString

android - 如何从 Android 正确调用 Java 中的非静态函数? (组合中的 Cocos2Dx)

使用 FreeImage 时 Android NDK 链接器错误 'Undefined reference to std::ios_base'