//GameScene.cpp
//cocos2d: GameScene constructor
//cocos2d: GameScene onEnter
//cocos2d: GameScene onEnterTransitionDidFinish
//cocos2d: HelloWorld constructor
//cocos2d: GameScene onExitTransitionDidStart
//cocos2d: GameScene onExit
//cocos2d: GameScene destructor
//cocos2d: HelloWorld onEnter
//cocos2d: HelloWorld onEnterTransitionDidFinish
//cocos2d: HelloWorld onExitTransitionDidStart
//cocos2d: HelloWorld onExit
//cocos2d: HelloWorld destructor
#include "GameScene.h"
#include "HelloWorldScene.h"
USING_NS_CC;
GameScene::GameScene( void )
{
log ( "GameScene constructor" );
}
GameScene::~GameScene( void )
{
log ( "GameScene destructor" );
}
cocos2d::Scene* GameScene::createScene()
{
auto scene = Scene::create(); //创建一个场景
auto layer = GameScene::create(); //创建一个图层
scene->addChild(layer);
return scene;
}
//初始化当前的图层
bool GameScene::init()
{
if (!Layer::init()) //初始化父类
return false ;
//获取屏幕大小
size = Director::getInstance()->getVisibleSize();
//auto size = Director::getInstance()->getWinSize();
//添加一个图片精灵
sprite = Sprite::create( "OnePiece_1.png" );
sprite->setPosition(Vec2(size.width/2, size.height/2));
this ->addChild(sprite);
auto delay = DelayTime::create(2);
//回调函数动作的使用!!!
sprite->runAction(Sequence::create(delay, CallFuncN::create(CC_CALLBACK_1(GameScene::menuCallback, this )), NULL));
return true ;
}
void GameScene::menuCallback(Ref* pSender)
{
Director::getInstance()->replaceScene(HelloWorld::createScene());
}
void GameScene::onEnter()
{
Layer::onEnter();
log ( "GameScene onEnter" );
}
void GameScene::onEnterTransitionDidFinish()
{
Layer::onEnterTransitionDidFinish();
log ( "GameScene onEnterTransitionDidFinish" );
}
void GameScene::onExit()
{
Layer::onExit();
log ( "GameScene onExit" );
}
void GameScene::onExitTransitionDidStart()
{
Layer::onExitTransitionDidStart();
log ( "GameScene onExitTransitionDidStart" );
}
|