Cocos2d 场景切换特效
来源:程序员人生 发布时间:2014-10-10 08:00:00 阅读次数:3528次
添加一个场景WelcomeScene
-
#include "WelcomeScene.h"
-
#include "GameScene.h"
-
-
using namespace cocos2d;
-
-
CCScene* WelcomeScene::scene()
-
{
-
CCScene * scene = NULL;
-
do
-
{
-
scene=CCScene::create();
-
-
WelcomeScene* gameScene=WelcomeScene::create();
-
scene->addChild(gameScene);
-
-
-
}while(0);
-
-
return scene;
-
}
-
-
bool WelcomeScene::init()
-
{
-
this->setTouchEnabled(true);
-
bool bRet = false;
-
do
-
{
-
CCSprite* pMap = CCSprite::create("welcome_bg.png");
-
CCSize size = CCDirector::sharedDirector()->getWinSize();
-
pMap->setPosition(ccp(size.width/2, size.height/2));
-
this->addChild(pMap, 0);
-
-
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
-
"StartGameNormal.png",
-
"StartGamePressed.png",
-
this,
-
menu_selector(WelcomeScene::menuStartCallback));
-
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
-
pMenu->setPosition(size.width/2,size.height/2);
-
this->addChild(pMenu, 1);
-
-
}while(0);
-
-
bRet=true;
-
-
return bRet;
-
}
-
-
-
void WelcomeScene::menuStartCallback(CCObject* pSender)
-
{
-
CCScene * scene=GameScene::scene();
-
CCDirector::sharedDirector()->replaceScene(scene);
-
}
在menuStartCallback()中通过导演来切换场景。
使用特效:
-
CCDirector::sharedDirector()->replaceScene((CCTransitionSlideInR::create(1, scene)));
网上找的特效:
CCTransitionJumpZoom::transitionWithDuration(t, s);//跳跃式,本场景先会缩小,然后跳跃进来
CCTransitionFade::transitionWithDuration(t, s);//淡出淡入,原场景淡出,新场景淡入
CCTransitionFade::transitionWithDuration(t, s, ccWHITE);//如果上一个的函数,带3个参数,则第三个参数就是淡出淡入的颜色
CCTransitionFlipX::transitionWithDuration(t, s, kOrientationLeftOver);//x轴左翻
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠