Cocos2d x 在cocos 2d-x中创建启动屏幕
您好,我正在cocos2d-x中创建一个游戏,当我在启动屏幕上为运行游戏安排一个事件时。它显示宏“schedule_selector”扩展中的编译错误 下面是我的代码 飞溅Cocos2d x 在cocos 2d-x中创建启动屏幕,cocos2d-x,Cocos2d X,您好,我正在cocos2d-x中创建一个游戏,当我在启动屏幕上为运行游戏安排一个事件时。它显示宏“schedule_selector”扩展中的编译错误 下面是我的代码 飞溅 #ifndef SPLASH_H_ #define SPLASH_H_ #include "cocos2d.h" class CCSplashLayer : public cocos2d::CCLayer { private : void runGame(); public: static cocos2d:
#ifndef SPLASH_H_
#define SPLASH_H_
#include "cocos2d.h"
class CCSplashLayer : public cocos2d::CCLayer {
private :
void runGame();
public:
static cocos2d::CCScene* createScene();
virtual bool init();
CREATE_FUNC(CCSplashLayer);
};
#endif /* SPLASH_H_ */
和splashsite.cpp
#include "splash.h"
#include "cocos2d.h"
#include "HelloWorldScene.h"
USING_NS_CC;
bool CCSplashLayer::init() {
if (!Layer::init()) {
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
auto sprite = Sprite::create("splash.png");
sprite->setScale(Director::getInstance()->getContentScaleFactor());
sprite->setPosition(Vec2(visibleSize.width / 2,visibleSize.height/2));
this->addChild(sprite, 0);
//This line cause problem show i symbol on this line in eclipse
this->scheduleOnce(schedule_selector(CCSplashLayer::runGame),4.0f);
return true;
}
Scene* CCSplashLayer::createScene() {
auto scene = CCScene::create();
auto layer = CCSplashLayer::create();
scene->addChild(layer);
return scene;
}
void CCSplashLayer::runGame(){
auto scene = HelloWorld::createScene();
Director::getInstance()->setDepthTest(true);
TransitionScene *transition = TransitionScene::create(0.5f, scene);
Director::getInstance()->pushScene(transition);
}
像这样试试。。。
在init方法中
this->runAction(CCSequence::create(CCDelayTime::create(4.0f),
CCCallFuncN::create(this,callfuncN_selector(CCSplashLayer::runGame)),
NULL));
并添加此方法
void CCSplashLayer::runGame(){
auto scene = HelloWorld::createScene();
Director::getInstance()->setDepthTest(true);
TransitionScene *transition = TransitionScene::create(0.5f, scene);
Director::getInstance()->pushScene(transition);
}
schedule_选择器采用函数指针,该指针需要一个浮点参数来表示时间
将定义和声明中的方法CCSplashLayer::runGame更改为CCSplashLayer::runGamefloat dt
此外,您正在将场景推到飞溅场景上,这不是飞溅场景的推荐方式。您必须用新场景替换飞溅场景,因为除非游戏有特定的设计要求,否则我们永远不需要在游戏中再次显示飞溅场景。尝试此宏:
#define CCDL_PERFORM_SELECTOR( __OWNER__, __DELAY__, __CALLFUNC_SELECTOR__ ) \
__OWNER__->runAction( cocos2d::Sequence::create( \
cocos2d::DelayTime::create( __DELAY__ ), \
cocos2d::CallFunc::create( CC_CALLBACK_0( __CALLFUNC_SELECTOR__,__OWNER__) ), \
nullptr )); \
资料来源:
允许用于任何CCNode+子类实例。
在您的情况下,将:
bool CCSplashLayer::init()
{
CCDL_PERFORM_SELECTOR( this, 4.f, CCSplashLayer::runGame );
}
确切的错误消息是什么?计划事件行在eclipse中显示i图标,并在宏“Schedule_selector”展开部分的悬停**上显示此消息**这只是警告还是实际错误?发布截图。你没有给我们提供足够的信息来明确地告诉你。你可以在我的另一篇文章中找到一个在cocos2d-x 3.4中添加飞溅场景的详细示例:这也会在eclipse中显示i图标,并在宏“callfuncN\u selector”的扩展中的鼠标悬停上显示此消息******-1这也会在Windows和Android编译器中给出错误。CCCallFuncN接受参数中包含CCNode*的函子。使用CCCallFunc或将函数runGame更改为runGameCCNode*nodein V2.2 CCCallFunc在android中运行良好。我使用MacOSX通过eclipse编译。我不知道COCOS2DX3.0+