gpt4 book ai didi

android - cocos2d-x 未定义引用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:19 26 4
gpt4 key购买 nike

寻求一些帮助,我是 cocos2dx 的新手并且在使用 Eclipse IDE 时遇到错误。

在 HelloWorld.cpp 中我这样做:

_backgroundNode = CCParallaxNodeExtras::node();

它给了我如下 undefined reference 错误

对“CCParallaxNodeExtras::node()”的 undefined reference

我的CCParallaxNodeExtras.h头文件代码如下它继承了CCParallaxNode

using namespace cocos2d;
#include "cocos2d.h"

class CCParallaxNodeExtras : public cocos2d::CCParallaxNode {

public :

// Need to provide a constructor
CCParallaxNodeExtras();

// just to avoid ugly later cast and also for safety
static CCParallaxNodeExtras* node();

// Facility method (it’s expected to have it soon in COCOS2DX)
void incrementOffset(CCPoint offset, CCNode* node);
};

#endif

这里是 CCParallaxNodeExtras.cpp

#include "CCParallaxNodeExtras.h"
using namespace cocos2d;

// Hack to access CCPointObject (which is not a public class)
class CCPointObject : cocos2d::CCObject {
CC_SYNTHESIZE(cocos2d::CCPoint, m_tRatio, Ratio)
CC_SYNTHESIZE(cocos2d::CCPoint, m_tOffset, Offset)
CC_SYNTHESIZE(cocos2d::CCNode *, m_pChild, Child) // weak ref
};

// Need to provide a constructor
CCParallaxNodeExtras::CCParallaxNodeExtras() {
cocos2d::CCParallaxNode(); // call parent constructor
}

CCParallaxNodeExtras* CCParallaxNodeExtras::node() {
return new CCParallaxNodeExtras::CCParallaxNode();
}

void CCParallaxNodeExtras::incrementOffset(cocos2d::CCPoint offset,CCNode *node){
for( unsigned int i = 0; i < m_pParallaxArray->num; i++) {
CCPointObject *point = (CCPointObject *)m_pParallaxArray->arr[i];
CCNode *curNode = point->getChild();
if( curNode->isEqual(node) ) {
point->setOffset( ccpAdd(point->getOffset(), offset) );
break;
}
}
}

请回复,我知道上面有很多代码,但我想知道我是否做错了什么。任何帮助或建议将不胜感激。谢谢!

问候,穆罕默德·塔希尔·阿什拉夫

最佳答案

必须将新cpp文件的引用添加到对应jni目录下的Android.mk中。

在我的例子中,“Android.mk”文件位于路径中:{PROJ_DIRECTORY}\proj.android\jni

编辑此文件,并添加对 CCParallaxNodeExtras cpp 的引用,如下所示:

LOCAL_SRC_FILES 部分,您当前拥有:

LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp

现在包括 CCParallasNodeExtras.cpp 。它应该如下所示:

LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/CCParallaxNodeExtras.cpp

这应该可以解决问题。构建并运行。

关于android - cocos2d-x 未定义引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17260935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com