Android cocos2d-x未定义引用
我是cocos2dx新手,在使用Eclipse IDE时出错,正在寻求帮助 在HelloWorld.cpp中,我正在这样做:Android cocos2d-x未定义引用,android,eclipse,cocos2d-iphone,cocos2d-x,Android,Eclipse,Cocos2d Iphone,Cocos2d X,我是cocos2dx新手,在使用Eclipse IDE时出错,正在寻求帮助 在HelloWorld.cpp中,我正在这样做: _backgroundNode = CCParallaxNodeExtras::node(); 它给出了未定义的参考误差,如下所示 对“CCParallaxNodeExtras::node()”的未定义引用 我的CCParallaxNodeExtras.h头文件代码如下,它继承了CCParallaxNode using namespace cocos2d; #inclu
_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
#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;
}
}
}
这里是CCParallaxNodeExtras.cpp
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
#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;
}
}
}
#包括“CCParallaxNodeExtras.h”
使用名称空间cocos2d;
//黑客访问CCPointObject(不是公共类)
类CCPointObject:cocos2d::CCObject{
CC_合成(cocos2d::CCPoint,m_,Ratio)
CC_合成(cocos2d::CCPoint,m_-tOffset,Offset)
CC_synthesis(cocos2d::CCNode*,m_pChild,Child)//弱引用
};
//需要提供一个构造函数
CCParallaxNodeExtras::CCParallaxNodeExtras(){
cocos2d::CCParallaxNode();//调用父构造函数
}
CCParallaxNodeExtras*CCParallaxNodeExtras::node(){
返回新的CCParallaxNodeExtras::CCParallaxNode();
}
void CCParallaxNodeExtras::incrementOffset(cocos2d::CCPoint offset,CCNode*节点){
for(无符号整数i=0;inum;i++){
CCPointObject*point=(CCPointObject*)m_pparlaraxarray->arr[i];
CCNode*curNode=point->getChild();
if(curNode->isEqual(node)){
点->设置偏移(ccpAdd(点->获取偏移(),偏移));
打破
}
}
}
请回复,我知道上面有很多代码,但我想知道我是否做错了什么。任何帮助或建议都将不胜感激。谢谢
问候,,
穆罕默德·塔希尔·阿什拉夫(Muhammad Tahir Ashraf)看起来您在定义CCParallaxNodeExtras::node()方法时遇到了问题。 应该是这样的:
CCParallaxNodeExtras* CCParallaxNodeExtras::node() {
return new CCParallaxNodeExtras();
}
我认为应该解决这个问题。如果没有,请告诉我。您必须将新cpp文件的引用添加到相应jni目录的Android.mk中 在我的例子中,“Android.mk”文件的路径是:{PROJ_DIRECTORY}\PROJ.Android\jni 编辑此文件,并将引用添加到CCParallaxNodeExtras cpp,如下所示:
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/CCParallaxNodeExtras.cpp
在本地\u SRC\u文件部分,您当前拥有:
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
这应该可以解决问题。构建并运行。谢谢你的回答,我尝试了这个,但仍然有相同的错误。。!!或者,只需添加
CLASSES\u文件:=$(CLASSES\u文件:$(LOCAL\u路径)/%=%)
然后添加LOCAL\u SRC\u文件+=$(CLASSES\u文件)
将不再需要手动添加。从这里了解到: