gpt4 book ai didi

android - Cocos2dx替换场景报错

转载 作者:行者123 更新时间:2023-11-28 07:30:33 25 4
gpt4 key购买 nike

Scenario 我有主场景,我点击这个按钮我想打开另一个场景。但我收到以下错误:对“OyunMenu::scene()”的 undefined reference

主菜单.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

主菜单.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文件

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

关于android - Cocos2dx替换场景报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com