Cocos2dx 3.0失败..build_native.py(Build to Android)

时间:2014-07-03 07:40:59

标签: android java-native-interface cocos2d-x cocos2d-x-3.0

CPP

#include "HelloWorldScene.h"

USING_NS_CC;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <string.h>
#include <jni.h>
extern
"C"
{
    JNIEXPORT jint JNICALL Java_org_cocos2dx_cpp_AppActivity_cppSum(JNIEnv* env, jobject obj)
    {
        MessageBox( "Call me From Java11", "JNI Test11" );

        HelloWorld::doFiring(); //I wan't excute.....
        log("CCCCCCCCCCC");
        return 121;
    }
}
#endif

Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();   
    auto layer = HelloWorld::create();
    scene->addChild(layer);
    return scene;
}

bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    return true;
}

void HelloWorld::doFiring()
{
    MessageBox( "Call me From Java11", "JNI Test11" );
}

构建此页面.. 错误消息:

[armeabi] Compile ++ thumb:cocos2dcpp_shared&lt; = HelloWorldScene.cpp jni /../../ Classes / HelloWorldScene.cpp:函数&#39; jint Java_org_cocos2dx_cpp_AppActivity_cppSum(JNIEnv *,jobject)&#39;: jni /../../ Classes / HelloWorldScene.cpp:19:24:错误:无法调用成员函数&#39; void HelloWorld :: doFiring()&#39;没有ob JECT    的HelloWorld :: doFiring();                         ^ make.exe: * [obj / local / armeabi / objs / cocos2dcpp_shared / / /Classes/HelloWorldScene.o]错误1

1 个答案:

答案 0 :(得分:0)

HelloWorld :: doFiring()不是静态函数。 你可以打电话     导演::的getInstance() - &GT; getRunningScene(); 得到场景,然后找到了具有消防功能的孩子。 也许你的代码应该像:

auto children = Director::getInstance()->getRunningScene()->getChildren();
for(auto child:children)
{
    auto layer = dynamic_cast<HelloWorld*>(child);
    if (layer) {
        layer.doFiring();
    }
}