cocos2d-x切换场景的32种动画代码
//--------------HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
public:
virtual bool init();
static cocos2d::CCScene* scene();
CREATE_FUNC(HelloWorld);
virtual ~HelloWorld();
void changeScene();
//生命周期函数
virtual void onEnter();
virtual void onEnterTransitionDidFinish();
virtual void onExit();
};
#endif // __HELLOWORLD_SCENE_H__
//--------------HelloWorldScene.cpp
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "TestLayer.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
returnscene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCLOG("HelloWorld init");
CCSprite * sp = CCSprite::create("background1.png");
sp->setPosition(ccp(240,160));
addChild(sp);
CCLabelTTF* labelTTF =CCLabelTTF::create("点击切换场景", "Helvetica-Hald",
30);
labelTTF->setColor(ccc3(255, 0, 0));
CCMenuItemLabel * labelItem = CCMenuItemLabel::create(labelTTF, this,
menu_selector(HelloWorld::changeScene));
CCMenu* menu= CCMenu::create(labelItem,NULL);
addChild(menu);
return true;
}
void HelloWorld::changeScene(){
CCTransitionScene* reScene =NULL;
CCScene* s =TestLayer::scene();
float t= 1.2f;
//--------CCTransitionJumpZoom--创建一个跳动的过渡动画
//reScene = CCTransitionJumpZoom::create(t,s);
//--------CCTransitionProgressRadialCCW-- 创建一个扇形进度条形式的过渡动画(逆时针)
//reScene = CCTransitionProgressRadialCCW::create(t,s);
//--------CCTransitionProgressRadialCW-- 创建一个扇形进度条形式的过渡动画(顺时针)
//reScene = CCTransitionProgressRadialCW::create(t,s);
//--------CCTransitionProgressHorizontal -- 创建一个水平进度条形式过渡动画
//reScene=CCTransitionProgressHorizontal::create(t, s);
//--------CCTransitionProgressVertical--创建一个垂直进度条形式过渡动画
//reScene=CCTransitionProgressVertical::create(t, s);
//--------CCTransitionProgressInOut--创建一个从里向外扩展的动画
//reScene=CCTransitionProgressInOut::create(t, s);
//--------CCTransitionProgressOutIn--创建一个从外向里扩展的动画
//reScene=CCTransitionProgressOutIn::create(t, s);
//--------CCTransitionCrossFade--创建一个逐渐透明的过渡动画
//reScene =CCTransitionCrossFade::create(t, s);
//--------CCTransitionPageTurn--创建一个翻页的过渡动画
//reScene =CCTransitionPageTurn::create(t, s, false);
//--------CCTransitionFadeTR--创建一个从左下到右上的过渡动画
//reScene = CCTransitionFadeTR::create(t, s);
//--------CCTransitionFadeBL
//reScene = CCTransitionFadeBL::create(t, s);
//--------CCTransitionFadeUp
//reScene = CCTransitionFadeUp::create(t, s);
//--------CCTransitionFadeDown
//reScene = CCTransitionFadeDown::create(t, s);
//--------CCTransitionTurnOffTiles--创建一个随机方格消失的过渡动画
//reScene = CCTransitionTurnOffTiles::create(t, s);
//--------CCTransitionSplitRows--创建一个分行划分切换的过渡动画
//reScene = CCTransitionSplitRows::create(t, s);
//--------CCTransitionSplitCols--创建一个分列划分的过渡动画
//reScene = CCTransitionSplitCols::create(t, s);
//--------CCTransitionFade--创建一个过渡到目标颜色的过渡动画
//reScene = CCTransitionFade::create(t, s,ccRED);
//-------- CCTransitionFlipX--创建一个X轴反转的过渡动画
//reScene=CCTransitionFlipX::create(t, s,kOrientationRightOver);
//--------CCTransitionFlipY--创建一个Y轴反转的过渡动画
//reScene=CCTransitionFlipY::create(t, s,kOrientationUpOver);
//--------CCTransitionFlipAngular--创建一个带有反转角的反转切换的过渡动画
//reScene=CCTransitionFlipAngular::create(t, s,kOrientationLeftOver);
//--------CCTransitionZoomFlipX--创建一个带有缩放的x轴反转的过渡动画
//reScene=CCTransitionZoomFlipX::create(t, s,kOrientationLeftOver);
//--------CCTransitionZoomFlipY--创建一个带有缩放的y轴反转的过渡动画
//reScene=CCTransitionZoomFlipY::create(t, s,kOrientationLeftOver);
//--------CCTransitionZoomFlipAngular--创建一个带有缩放、反转的过渡动画
//reScene = CCTransitionZoomFlipAngular::create(t,
s,kOrientationLeftOver);
//--------CCTransitionShrinkGrow--创建一个带有缩放交替的过渡动画
//reScene = CCTransitionShrinkGrow::create(t, s);
//--------CCTransitionRotoZoom--创建一个带有旋转缩放的过渡动画
//reScene = CCTransitionRotoZoom::create(t, s);
//--------CCTransitionMoveInL--创建一个从左侧推入覆盖的过渡动画
//reScene=CCTransitionMoveInL::create(t, s);
//--------CCTransitionMoveInR--创建一个从右侧推入覆盖的过渡动画
//reScene=CCTransitionMoveInR::create(t, s);
//--------CCTransitionMoveInT
//reScene=CCTransitionMoveInT::create(t, s);
//--------CCTransitionMoveInB
//reScene=CCTransitionMoveInB::create(t, s);
//--------CCTransitionSlideInL--创建一个从左侧推入并顶出旧场景的过渡动画
//reScene = CCTransitionSlideInL::create(t, s);
//--------CCTransitionSlideInR--创建一个从右侧推入并顶出旧场景的过渡动画
//reScene = CCTransitionSlideInR::create(t, s);
//--------CCTransitionSlideInT
//reScene = CCTransitionSlideInT::create(t, s);
//--------CCTransitionSlideInB
reScene = CCTransitionSlideInB::create(t, s);
CCDirector::sharedDirector()->replaceScene(reScene);
}
void HelloWorld::onEnter(){
CCLOG("HelloWorld onEnter");
CCLayer::onEnter();//务必调用
}
void HelloWorld::onEnterTransitionDidFinish(){
CCLOG("HelloWorld onEnterTransitionDidFinish");
CCLayer::onEnterTransitionDidFinish();//务必调用
}
void HelloWorld::onExit(){
CCLOG("HelloWorld onExit");
CCLayer::onExit();//务必调用
}
HelloWorld:: ~HelloWorld(){
CCLOG("HelloWorld 析构");
}
//------------------------TestLayer.h
//
//TestLayer.h
//ReplaceSceneTest
//
//Created by Himi on 12-9-12.
//
//
#ifndef __ReplaceSceneTest__TestLayer__
#define __ReplaceSceneTest__TestLayer__
#include "cocos2d.h"
class TestLayer : public cocos2d::CCLayer
{
public:
virtual bool init();
static cocos2d::CCScene* scene();
CREATE_FUNC(TestLayer);
virtual void onEnter();
virtual void onEnterTransitionDidFinish();
virtual void onExit();
};
#endif /* defined(__ReplaceSceneTest__TestLayer__) */
//-------------------------------TestLayer.cpp
//
//TestLayer.cpp
//ReplaceSceneTest
//
//Created by Himi on 12-9-12.
//
//
#include "TestLayer.h"
using namespace cocos2d;
CCScene* TestLayer::scene()
{
CCScene *scene = CCScene::create();
TestLayer *layer = TestLayer::create();
scene->addChild(layer);
return scene;
}
bool TestLayer::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCLOG("TestLayer init");
CCSprite * sp = CCSprite::create("background2.png");
sp->setPosition(ccp(240,160));
addChild(sp);
return true;
}
//进入此类中的调用函数
void TestLayer::onEnter(){
CCLOG("TestLayer onEnter");
CCLayer::onEnter();
}
//切换动画完成后调用的函数
void TestLayer::onEnterTransitionDidFinish(){
CCLOG("TestLayer onEnterTransitionDidFinish");
CCLayer::onEnterTransitionDidFinish();
}
//退出时候调用的函数
void TestLayer::onExit(){
CCLOG("TestLayer onExit");
CCLayer::onExit();
}
页:
[1]