【问题标题】:Cocos2dx 3.0 Failed ..build_native.py ( Build to Android)Cocos2dx 3.0 失败 ..build_native.py(构建到 Android)
【发布时间】:2014-07-03 07:40:59
【问题描述】:

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] 编译++ thumb:cocos2dcpp_shared * [obj/local/armeabi/objs/cocos2dcpp_shared///Classes/HelloWorldScene.o] 错误1

.

【问题讨论】:

  • 听起来 doFiring 没有声明为静态的,而是一个成员函数,但您将其称为静态类方法:HelloWorld::doFiring()

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


【解决方案1】:

HelloWorld::doFiring() 不是静态函数。 你可以打电话 导演::getInstance()->getRunningScene(); 到现场,然后找到有做火功能的孩子。 也许你的代码应该是这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2018-06-09
    • 2018-10-15
    • 2016-10-17
    • 2017-06-08
    相关资源
    最近更新 更多