Cocos2dx替换了错误

时间:2013-07-24 08:51:45

标签: android c++ cocos2d-iphone

场景我有主场景,我点击这个按钮我要打开另一个场景。但我收到以下错误: 未定义引用'OyunMenu :: scene()

MainMenu.h

 #ifndef MAINMENU_H_
#define MAINMENU_H_

#include "cocos2d.h"

    class MainMenu : public cocos2d::CCLayer
    {
    public:
virtual bool init();


static cocos2d::CCScene* scene();
virtual void registerWithTouchDispatcher(void);
virtual void ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesCancelled(cocos2d::CCSet* touches, cocos2d::CCEvent* event);

void menuCloseCallback(CCObject* pSender);

CREATE_FUNC(MainMenu);


};


#endif 

MainMenu.cpp

#include "MainMenu.h"
#include "SimpleAudioEngine.h"
#include "Constants.h"
#include "OyunMenu.h"

#define COCOS2D_DEBUG 1

using namespace std;
USING_NS_CC;

 CCScene* MainMenu::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
MainMenu *layer = MainMenu::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
 }



bool MainMenu::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
    return false;
}   


this->setTouchEnabled(true);

CCSprite* oyuncuBul = CCSprite::create("oyuna-basla.png");
oyuncuBul->setPosition(ccp(150,260));
oyuncuBul->setTag(menuOyuncuBul);
this->addChild(oyuncuBul, 0); 
}

    void MainMenu::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
    {
CCTouch *touch = (CCTouch*) (touches->anyObject());
CCPoint point = touch->getLocationInView();
point = CCDirector::sharedDirector()->convertToGL(point);

CCSprite *oyuncuBul=(CCSprite *)this->getChildByTag(menuOyuncuBul);

CCRect rectOyuncuBul = oyuncuBul->boundingBox();

if(rectOyuncuBul.containsPoint(point)){
    CCDirector::sharedDirector()->replaceScene(OyunMenu::scene());          
}

OyunMenu.h

#ifndef OYUNMENU_H_
#define OYUNMENU_H_

#include "cocos2d.h"

class OyunMenu : public cocos2d::CCLayer
{
 public:
virtual bool init();


static cocos2d::CCScene* scene();
virtual void registerWithTouchDispatcher(void);
virtual void ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesCancelled(cocos2d::CCSet* touches, cocos2d::CCEvent* event);

void menuCloseCallback(CCObject* pSender);

CREATE_FUNC(OyunMenu);


};


#endif 

OyunMenu.cpp

#include "OyunMenu.h"
#include "SimpleAudioEngine.h"
#include "Constants.h"

#define COCOS2D_DEBUG 1

using namespace std;
USING_NS_CC;

CCScene* OyunMenu::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
OyunMenu *layer = OyunMenu::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}


// on "init" you need to initialize your instance
 bool OyunMenu::init()
{ 
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
    return false;
}
}

2 个答案:

答案 0 :(得分:1)

.h文件

CCSprite* oyuncuBul;

.cpp文件

oyuncuBul = CCSprite::create("oyuna-basla.png");
oyuncuBul->setPosition(ccp(150,260));
oyuncuBul->setTag(menuOyuncuBul);
this->addChild(oyuncuBul, 0); 





void MainMenu::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
        {
    CCTouch *touch = (CCTouch*) (touches->anyObject());
    CCPoint point = touch->getLocationInView();
    point = CCDirector::sharedDirector()->convertToGL(point);



    CCRect rectOyuncuBul = oyuncuBul->boundingBox();

    if(rectOyuncuBul.containsPoint(point)){
        CCDirector::sharedDirector()->replaceScene(OyunMenu::scene());          
    }

答案 1 :(得分:0)

你必须在jni文件夹

的android.mk文件中添加这一行

../../类/ OyunMenu.cpp

就像我在android.mk文件中添加

一样

LOCAL_SRC_FILES:= hellocpp / main.cpp \

               ../../Classes/Menu/AppDelegate.cpp\
               ../../Classes/Menu/HelloWorldScene.cpp\
               ../../Classes/Menu/MyScene.cpp\
               ../../Classes/Menu/LoadingLayer.cpp\
               ../../Classes/UI/NewLayer.cpp\
               ../../Classes/UI/HelpLayer.cpp