4

Looking for some help,Iam new to cocos2dx and having error.iam using Eclipse IDE

inside HelloWorld.cpp iam doing this:

_backgroundNode = CCParallaxNodeExtras::node();

and it gives me undefined reference error which is as follows

undefined reference to 'CCParallaxNodeExtras::node()'

My CCParallaxNodeExtras.h header file code is as follows it inherits 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

here is the 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;
        }
    }
}

Please Reply, I Know there is a lot of code above but i want to know if iam doing anything wrong.Any Help or suggesstion will be appreciated.Thanks!

Regards, Muhammad Tahir Ashraf

4

2 に答える 2

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

これで問題は解決するはずです。ビルドして実行します。

于 2013-06-25T06:43:21.880 に答える
1

CCParallaxNodeExtras::node() メソッドの定義に問題があるようです。次のようになります。

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

問題を解決する必要があると思います。そうでない場合はお知らせください。

于 2013-06-23T15:46:37.297 に答える