本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
各种场景切换过渡效果
///cocos2d-x-3.0alpha0/cocos2dx/layers_scenes_transitions_nodes //各种场景切换过渡效果 #ifndef __CCTRANSITION_H__ #define __CCTRANSITION_H__ #include "CCScene.h" #include "ccTypes.h" NS_CC_BEGIN /** * @addtogroup transition * @{ */ //static creation function macro(宏) //c/c++ 不支持使用 class name 创建 //所以每个类都需要创建方法. class ActionInterval; class Node; /** @brief TransitionEaseScene 可以放缓动作的 scene 协议 @since v0.8.2 */ class CC_DLL TransitionEaseScene// : public Object { public: /** returns 将在线性 action 上执行的Ease(放缓) action @since v0.8.2 */ virtual ActionInterval * easeActionWithAction(ActionInterval * action) = 0; }; /** @brief Base class for Transition scenes */ class CC_DLL TransitionScene : public Scene { public: /** 一些 transitions 使用的类型取向 */ enum class Orientation { /// 水平向左对齐 LEFT_OVER = 0, /// 水平向右对齐 RIGHT_OVER = 1, /// 垂直向上对齐 UP_OVER = 0, /// 垂直向下对齐 DOWN_OVER = 1, }; /** 使用 duration、incoming(传入的 seene 创建一个 基本过渡 */ static TransitionScene * create(float t, Scene *scene); /** * @js ctor */ TransitionScene(); /** * @js NA * @lua NA */ virtual ~TransitionScene(); /** 使用 duration、incoming(传入的 seene 初始化一个 基本过渡 */ bool initWithDuration(float t,Scene* scene); /** 过渡完成后调用 */ void finish(void); /** 使用它隐藏一些 scene */ void hideOutShowIn(void); // // Overrides // virtual void draw() override; /** * @js NA * @lua NA */ virtual void onEnter() override; /** * @js NA * @lua NA */ virtual void onExit() override; virtual void cleanup() override; protected: virtual void sceneOrder(); private: void setNewScene(float dt); protected: Scene * _inScene; Scene * _outScene; float _duration; bool _isInSceneOnTop; bool _isSendCleanupToScene; }; /** @brief 想一个支持方向的过渡. * 可能的方向: LeftOver, RightOver, UpOver, DownOver */ class CC_DLL TransitionSceneOriented : public TransitionScene { public: /** 使用 duration、incoming(传入的) seene 创建一个 基本过渡 */ static TransitionSceneOriented * create(float t,Scene* scene, Orientation orientation); /** * @js ctor */ TransitionSceneOriented(); /** * @js NA * @lua NA */ virtual ~TransitionSceneOriented(); /** 使用 duration、incoming(传入的) seene 初始化一个过渡 */ bool initWithDuration(float t,Scene* scene,Orientation orientation); protected: Orientation _orientation; }; /** @brief TransitionRotoZoom: 旋转缩放淡出 scene ,旋转缩放淡入 scene */ class CC_DLL TransitionRotoZoom : public TransitionScene { public: static TransitionRotoZoom* create(float t, Scene* scene); TransitionRotoZoom(); /** * @js NA * @lua NA */ virtual ~TransitionRotoZoom(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionJumpZoom: 缩放跳跃淡出 scene, 缩放跳跃淡入 scene */ class CC_DLL TransitionJumpZoom : public TransitionScene { public: static TransitionJumpZoom* create(float t, Scene* scene); /** * @js ctor */ TransitionJumpZoom(); /** * @js NA * @lua NA */ virtual ~TransitionJumpZoom(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionMoveInL: 从左边传入 scene */ class CC_DLL TransitionMoveInL : public TransitionScene, public TransitionEaseScene { public: static TransitionMoveInL* create(float t, Scene* scene); /** * @js ctor */ TransitionMoveInL(); /** * @js NA * @lua NA */ virtual ~TransitionMoveInL(); /** 初始化一个 scenes */ virtual void initScenes(void); /** returns 将要执行的 action */ virtual ActionInterval* action(void); virtual ActionInterval* easeActionWithAction(ActionInterval * action); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionMoveInR: 从右边传入 scene. */ class CC_DLL TransitionMoveInR : public TransitionMoveInL { public: static TransitionMoveInR* create(float t, Scene* scene); /** * @js ctor */ TransitionMoveInR(); /** * @js NA * @lua NA */ virtual ~TransitionMoveInR(); virtual void initScenes(); }; /** @brief TransitionMoveInT: 从顶部传入 scene. */ class CC_DLL TransitionMoveInT : public TransitionMoveInL { public: static TransitionMoveInT* create(float t, Scene* scene); /** * @js ctor */ TransitionMoveInT(); /** * @js NA * @lua NA */ virtual ~TransitionMoveInT(); virtual void initScenes(); }; /** @brief TransitionMoveInB: 从底部传入 scene. */ class CC_DLL TransitionMoveInB : public TransitionMoveInL { public: static TransitionMoveInB* create(float t, Scene* scene); /** * @js ctor */ TransitionMoveInB(); /** * @js NA * @lua NA */ virtual ~TransitionMoveInB(); virtual void initScenes(); }; /** @brief TransitionSlideInL: 从左边界slide(滑动)传入 scene. */ class CC_DLL TransitionSlideInL : public TransitionScene, public TransitionEaseScene { public: static TransitionSlideInL* create(float t, Scene* scene); /** * @js ctor */ TransitionSlideInL(); /** * @js NA * @lua NA */ virtual ~TransitionSlideInL(); virtual ActionInterval* easeActionWithAction(ActionInterval * action); /** 初始化 scenes */ virtual void initScenes(void); /** returns 传入/传出 scene 要执行的 action */ virtual ActionInterval* action(void); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; protected: virtual void sceneOrder() override; }; /** @brief TransitionSlideInR: 从右边界slide(滑动)传入 scene. */ class CC_DLL TransitionSlideInR : public TransitionSlideInL { public: static TransitionSlideInR* create(float t, Scene* scene); /** * @js ctor */ TransitionSlideInR(); /** * @js NA * @lua NA */ virtual ~TransitionSlideInR(); /** 初始化 scenes */ virtual void initScenes(void); /** returns传入/传出 scene 要执行的 action */ virtual ActionInterval* action(void); protected: virtual void sceneOrder() override; }; /** @brief TransitionSlideInB: 从底部边界slide(滑动)传入 scene.. */ class CC_DLL TransitionSlideInB : public TransitionSlideInL { public: static TransitionSlideInB* create(float t, Scene* scene); /** * @js ctor */ TransitionSlideInB(); /** * @js NA * @lua NA */ virtual ~TransitionSlideInB(); /** 初始化 scenes */ virtual void initScenes(void); /** returns 传入/传出 scene 要执行的 action */ virtual ActionInterval* action(void); protected: virtual void sceneOrder() override; }; /** @brief TransitionSlideInT: 从顶部界slide(滑动)传入 scene.. */ class CC_DLL TransitionSlideInT : public TransitionSlideInL { public: static TransitionSlideInT* create(float t, Scene* scene); /** * @js ctor */ TransitionSlideInT(); /** * @js NA * @lua NA */ virtual ~TransitionSlideInT(); /** 初始化 scenes */ virtual void initScenes(void); /** returns 传入/传出 scene 要执行的 action */ virtual ActionInterval* action(void); protected: virtual void sceneOrder() override; }; /** @brief 当增加传入 scene 的时候,收缩传出的 scene */ class CC_DLL TransitionShrinkGrow : public TransitionScene , public TransitionEaseScene { public: static TransitionShrinkGrow* create(float t, Scene* scene); /** * @js ctor */ TransitionShrinkGrow(); /** * @js NA * @lua NA */ virtual ~TransitionShrinkGrow(); // // Overrides // virtual void onEnter() override; virtual ActionInterval* easeActionWithAction(ActionInterval * action) override; }; /** @brief TransitionFlipX: 水平翻转屏幕。 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionFlipX : public TransitionSceneOriented { public: static TransitionFlipX* create(float t, Scene* s, Orientation o); static TransitionFlipX* create(float t, Scene* s); /** * @js ctor */ TransitionFlipX(); /** * @js NA * @lua NA */ virtual ~TransitionFlipX(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionFlipY: 垂直翻转屏幕。. 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionFlipY : public TransitionSceneOriented { public: static TransitionFlipY* create(float t, Scene* s, Orientation o); static TransitionFlipY* create(float t, Scene* s); /** * @js ctor */ TransitionFlipY(); /** * @js NA * @lua NA */ virtual ~TransitionFlipY(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionFlipAngular: 水平垂直翻转一半屏幕.(类似一种镜面) 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionFlipAngular : public TransitionSceneOriented { public: static TransitionFlipAngular* create(float t, Scene* s, Orientation o); static TransitionFlipAngular* create(float t, Scene* s); /** * @js ctor */ TransitionFlipAngular(); /** * @js NA * @lua NA */ virtual ~TransitionFlipAngular(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionZoomFlipX: 水平翻转屏幕,做一个 传入/穿出 缩放 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionZoomFlipX : public TransitionSceneOriented { public: static TransitionZoomFlipX* create(float t, Scene* s, Orientation o); static TransitionZoomFlipX* create(float t, Scene* s); /** * @js ctor */ TransitionZoomFlipX(); /** * @js NA * @lua NA */ virtual ~TransitionZoomFlipX(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionZoomFlipY: 垂直翻转屏幕,做一个 传入/穿出 缩放 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionZoomFlipY : public TransitionSceneOriented { public: static TransitionZoomFlipY* create(float t, Scene* s, Orientation o); static TransitionZoomFlipY* create(float t, Scene* s); /** * @js ctor */ TransitionZoomFlipY(); /** * @js NA * @lua NA */ virtual ~TransitionZoomFlipY(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionZoomFlipAngular: 一半水平一半垂直 传入/穿出 翻转并一点点的缩放屏幕 正面是传出的场景,背面是传入的场景。 */ class CC_DLL TransitionZoomFlipAngular : public TransitionSceneOriented { public: static TransitionZoomFlipAngular* create(float t, Scene* s, Orientation o); static TransitionZoomFlipAngular* create(float t, Scene* s); /** * @js ctor */ TransitionZoomFlipAngular(); /** * @js NA * @lua NA */ virtual ~TransitionZoomFlipAngular(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; }; /** @brief TransitionFade: 淡出传出 scene ,淡入传入 scene.''' */ class CC_DLL TransitionFade : public TransitionScene { public: /** 使用 duration、RGB color 创建一个 transition(过渡) * Example: FadeTransition::create(2, scene, Color3B(255,0,0); // red color */ static TransitionFade* create(float duration,Scene* scene, const Color3B& color); static TransitionFade* create(float duration,Scene* scene); /** * @js ctor */ TransitionFade(); /** * @js NA * @lua NA */ virtual ~TransitionFade(); /** 使用 duration、RGB color 初始化一个 transition(过渡) */ bool initWithDuration(float t, Scene*scene ,const Color3B& color); // // Overrides // bool initWithDuration(float t,Scene* scene); /** * @js NA * @lua NA */ virtual void onEnter(); /** * @js NA * @lua NA */ virtual void onExit(); protected: Color4B _color; }; class RenderTexture; /** @brief TransitionCrossFade: 两个 scenes 使用 RenderTexture 对象交叉淡入淡出 */ class CC_DLL TransitionCrossFade : public TransitionScene { public : static TransitionCrossFade* create(float t, Scene* scene); /** * @js ctor */ TransitionCrossFade(); /** * @js NA * @lua NA */ virtual ~TransitionCrossFade(); // // Overrides // virtual void draw() override; /** * @js NA * @lua NA */ virtual void onEnter() override; /** * @js NA * @lua NA */ virtual void onExit() override; }; /** @brief TransitionTurnOffTiles: 随机顺序关闭淡出场景的 tiles */ class CC_DLL TransitionTurnOffTiles : public TransitionScene ,public TransitionEaseScene { public : static TransitionTurnOffTiles* create(float t, Scene* scene); /** * @js ctor */ TransitionTurnOffTiles(); /** * @js NA * @lua NA */ virtual ~TransitionTurnOffTiles(); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; protected: virtual void sceneOrder() override; }; /** @brief TransitionSplitCols: 奇数列向上推移而偶数列向下推移. */ class CC_DLL TransitionSplitCols : public TransitionScene , public TransitionEaseScene { public: static TransitionSplitCols* create(float t, Scene* scene); /** * @js ctor */ TransitionSplitCols(); /** * @js NA * @lua NA */ virtual ~TransitionSplitCols(); virtual ActionInterval* action(void); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; }; /** @brief TransitionSplitRows: 奇数行行从左侧推移,偶数行从右侧推移. */ class CC_DLL TransitionSplitRows : public TransitionSplitCols { public: static TransitionSplitRows* create(float t, Scene* scene); /** * @js ctor */ TransitionSplitRows(); /** * @js NA * @lua NA */ virtual ~TransitionSplitRows(); // // Overrides // virtual ActionInterval* action(void) override; }; /** @brief TransitionFadeTR: 从从左下角到右上角淡出 scene 的所有 tiles. */ class CC_DLL TransitionFadeTR : public TransitionScene , public TransitionEaseScene { public: static TransitionFadeTR* create(float t, Scene* scene); /** * @js ctor */ TransitionFadeTR(); /** * @js NA * @lua NA */ virtual ~TransitionFadeTR(); virtual ActionInterval* actionWithSize(const Size& size); // // Overrides // /** * @js NA * @lua NA */ virtual void onEnter() override; virtual ActionInterval* easeActionWithAction(ActionInterval * action) override; protected: virtual void sceneOrder(); }; /** @brief TransitionFadeBL: 从右上角到左下角淡出 scene 的所有 tiles. */ class CC_DLL TransitionFadeBL : public TransitionFadeTR { public: static TransitionFadeBL* create(float t, Scene* scene); /** * @js ctor */ TransitionFadeBL(); /** * @js NA * @lua NA */ virtual ~TransitionFadeBL(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; }; /** @brief TransitionFadeUp: //淡入过渡 * 从下向上淡出 scene 的所有 tiles. */ class CC_DLL TransitionFadeUp : public TransitionFadeTR { public: static TransitionFadeUp* create(float t, Scene* scene); /** * @js ctor */ TransitionFadeUp(); /** * @js NA * @lua NA */ virtual ~TransitionFadeUp(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; }; /** @brief TransitionFadeDown: //淡出过渡 * 从上向下淡出 scene 的所有 tiles. */ class CC_DLL TransitionFadeDown : public TransitionFadeTR { public: static TransitionFadeDown* create(float t, Scene* scene); /** * @js ctor */ TransitionFadeDown(); /** * @js NA * @lua NA */ virtual ~TransitionFadeDown(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; }; // end of transition(过渡) group /// @} NS_CC_END #endif // __CCTRANSITION_H__