寻求帮助,Iam对cocos2dx不熟悉并使用 Eclipse IDE
进行错误。 在HelloWorld.cpp中我这样做:
_backgroundNode = CCParallaxNodeExtras::node();
它给出了未定义的引用错误,如下所示
对'CCParallaxNodeExtras :: node()'
的未定义引用我的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;
}
}
}
请回复,我知道上面有很多代码,但我想知道我是否做错了什么。任何帮助或建议将不胜感激。谢谢!
此致 穆罕默德塔希尔阿什拉夫
答案 0 :(得分:15)
您必须将新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
这应该可以解决问题。建立并运行。
答案 1 :(得分:1)
您在CCParallaxNodeExtras :: node()方法的定义中看起来有问题。 应该是这样的:
CCParallaxNodeExtras* CCParallaxNodeExtras::node() {
return new CCParallaxNodeExtras();
}
我认为应该解决这个问题。如果没有,请告诉我。