简体   繁体   中英

Cocos2dx replacescene error

Scenario I have main scene and I click this button I want to open another scene. But I am getting following error : undefined reference to '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;
}
}

.h file

CCSprite* oyuncuBul;

.cpp file

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());          
    }

You have to add this line in android.mk file of jni folder

../../Classes/OyunMenu.cpp

Just like i am added in my android.mk file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM