Cocos2d-x 3.2 Study Notes (7) scene and transition

Source: Internet
Author: User

Scene scenario.

Is an abstract concept and is used only as a subclass of a node.

Scene and node are almost the same. The difference is that scene's default anchor is located in the center of the screen.

We have to mention switching between scenarios! The results are amazing! Let's take a look at the 33 switching effects. You can select and scale them as needed.

#ifndef __SceneTest__#define __SceneTest__#include "cocos2d.h"USING_NS_CC;class SceneTest : public Layer{public:    static Scene* createScene();    CREATE_FUNC(SceneTest);    virtual bool init();    bool onToucheBegans(Touch* touch,Event* ev);};class SceneConfig{public:    static SceneConfig* getInstance();    int getIndex();    void setIndex(int index);    std::string getBg();protected:private:        };#endif
Scenetest. h
# Include "scenetest. H "static const char s_bg1 [] =" background1.png "; static const char s_bg2 [] =" helloworld.png "; # define STR (name) # name # define Cl (classname) [] () {auto scene = classname: Create (1.2f, scenetest: createscene (); log (STR (classname); Return scene ;} # define CLN (classname) [] () {auto scene = classname: Create (1.2f, scenetest: createscene (), false); log (STR (classname )); return scene;} # Define c Ls (classname) [] () {auto scene = classname: Create (1.2f, scenetest: createscene (), ccc3( 255, 0, 0 )); log (STR (classname); Return scene ;}# define CLM (classname) [] () {auto scene = classname: Create (1.2f, scenetest: createscene (), transitionscene: orientation: left_over); log (STR (classname); Return scene;} static STD: function <SCENE * ()> createfunctions [] = {Cl (transitionjumpzoom), // role: Create a beating transition animation Cl (tr Ansitionprogressradialccw), // role, clockwise Cl (transitionprogresshorizontal), // role: Create a horizontal transition animation Cl (transitionprogressvertical), // role: Create a vertical transition animation Cl (transitionprogressinout ), // role: create a transitional animation Cl (transitionprogressoutin) that is extended from the inside to the outside. // role: create a transitional animation Cl (transitioncrossfade) that is extended from the outside. // role: create a gradually transparent transition animation Cl (transitionfadetr). // role: Create A blog transition animation, from lower left to upper right Cl (transitionfadebl). // role: Create a blog transition animation, from upper right to lower left Cl (transitionfadeup). // role: create a bottom-to-top transition animation Cl (transitionfadedown), // role: Create a transition animation Cl (transitionturnofftiles) from top to bottom, // role: create a transition animation Cl (transitionsplitrows) with a random square disappear. // role: Create a transition animation Cl (transitionsplitcols) for branch division switching. // role: create a transition animation Cl (transitionshrinkgrow), // create a transition animation Cl (transitionrotozoom), // create a transition animation Cl (transitionmo) Veinl), // role: create a transitional animation Cl (transitionmoveinr) pushed from the Left to overwrite, // role: create a transitional animation Cl (transitionmoveinb) pushed from the right to overwrite ), // role: create a transitional animation Cl (transitionmoveint) pushed from the bottom to overwrite. // role: create a transitional animation Cl (transitionslideinl) pushed from the top to overwrite. // role: create a transition animation Cl (transitionslideinr) That is pushed from the left to the original scene. // role: Create a transition animation Cl (transitionslideint) That is pushed from the right to the old scene ), // role: create a transitional animation Cl (transitionslideinb) That is pushed from the top and pushed out of the old scene. // role: create a transition animation CLN (transitionpageturn) pushed from the lower part and pushed out the old scene. // role: Create Transition animation Cls (transitionfade), // function: Create a switch animation CLM (transitionflipx) that gradually transitions to the target color. // function: create a switching animation CLM (transitionflipy) for X axis reversal. // role: Create a switching animation CLM (transitionflipangular) for Y axis reversal. // role: create an animation CLM with Reverse Rotation switching (transitionzoomflipx), // role: Create an animation CLM (transitionzoomflipy) with zoom X axis reversal switching, // role: create an animation CLM (transitionzoomflipangular) with scaling Y axis reversal switching. // role: Create an animation with scaling and Reverse Rotation switching}; SCENE * scenetest: createscene () {auto scene = scene: Create (); Auto layer = scenetest: Create (); scene-> addchild (layer); Return scene;} bool scenetest: Init () {auto sprite = sprite: Create (sceneconfig:: getinstance ()-> getbg (); size visiblesize = Director: getinstance ()-> getvisiblesize (); vec2 origin = Director: getinstance () -> getvisibleorigin (); sprite-> setposition (vec2 (visiblesize. width/2 + origin. x, visiblesize. height/2 + origin. y); this-> addchild (sprite, 0); Auto eventlistener = listener: Create (); eventlistener-> ontouchbegan = cc_callback_2 (scenetest: ontouchebegans, this); this-> _ eventdispatcher-> listener (eventlistener, this); Return true ;}# define max_layer (sizeof (createfunctions)/sizeof (createfunctions [0]) bool scenetest: ontouchebegans (touch * touch, event * eV) {auto idx = sceneconfig: getinstance ()-> Getindex (); idx ++; idx = idx % max_layer; sceneconfig: getinstance ()-> setindex (idx ); auto rescene = createfunctions [idx] (); Director: getinstance ()-> setdepthtest (false); Director: getinstance ()-> replacescene (rescene); Return true ;} static sceneconfig * config; static int _ index; sceneconfig * sceneconfig: getinstance () {If (! Config) {Config = new sceneconfig (); _ Index = 0;} return config;} int sceneconfig: getindex () {return _ index;} void sceneconfig :: setindex (INT index) {_ Index = index;} STD: String sceneconfig: getbg () {auto Index = _ index; If (index % 2> 0) {return s_bg1;} else {return s_bg2 ;}}
Scenetest. cpp

Click the screen to see the effect.

CL (transitionjumpzoom), // role: Create a beating transition animation Cl (transitionprogressradialccw), // role: create a sector-shaped transition animation, counterclockwise Cl (transitionprogressradialcw ), // role: Create a transition animation in the form of a slice, and clockwise Cl (transitionprogresshorizontal). // role: Create a horizontal transition animation Cl (transitionprogressvertical). // role: create a vertical transition animation Cl (transitionprogressinout), // role: Create a transition animation Cl (transitionprogressoutin), // role: create a transition animation Cl (transitioncrossfade) that is extended from the external, // role: Create a gradually transparent transition animation Cl (transitionfadetr), // role: Create a blog transition animation, from lower left to upper right Cl (transitionfadebl), // role: Create a blog transition animation, from upper right to lower left Cl (transitionfadeup), // role: Create a bottom-up, transition animation Cl (transitionfadedown) for bar folding, // role: Create a transition animation Cl (transitionturnofftiles) for bar folding, // role: create a transition animation Cl (transitionsplitrows) with a random square disappear. // role: Create a transition animation Cl (transitionsplitcols) for branch division switching. // role: create a transition animation Cl (transitionshrinkgrow) for division and switch, // create a transition animation Cl (transitionrotozoom) with an alternative contraction ), // create a transition animation Cl (transitionmoveinl), // role: Create a transition animation Cl (transitionmoveinr) pushed from the left, // role: create a transitional animation Cl (transitionmoveinb) pushed from the right, // role: create a transitional animation Cl (transitionmoveint) pushed from the bottom, // role: create a transitional animation Cl (transitionslideinl) pushed from the top to overwrite. // role: create a transitional animation Cl (transitionslideinr) pushed from the left to the top of the old scene. // role: create a transition animation Cl (transitionslideint) That is pushed from the right to the original scene. // role: Create a transition animation Cl (transitionslideinb) That is pushed from the top to the old scene ), // role: Create a transition animation CLN (transitionpageturn) pushed from the lower part and pushed out the old scene. // role: Create a paging transition animation Cls (transitionfade). // role: create a switching animation CLM (transitionflipx) that gradually transitions to the target color. // role: Create a switching animation CLM (transitionflipy) with X axis reversal. // role: create a switching animation CLM (transitionflipangular) with Y axis reversal. // role: Create an animation CLM (transitionzoomflipx) with Reverse Rotation. // role: create an animation CLM (transitionzoomflipy) with a scaled X axis reversal switch. // role: Create an animation CLM (transitionzoomflipangular) with a scaled Y axis reversal switch. // role: create an animation with scaling and Reverse Rotation Switching

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.