Cocos2d-x 3.2 Monopoly game project development-Part 2 titles animation, cocos2d-x Project Development

Source: Internet
Author: User

Cocos2d-x 3.2 Monopoly game project development-Part 2 titles animation, cocos2d-x Project Development

Part 2 Title Animation




Create a new project under visula studio

Tool class ConstUtil. h. This file mainly defines some image resources, strings, fonts, etc.

# Ifndef _ CONSTUTIL_H __# define _ CONSTUTIL_H _ // defines four image resources of chengmai technology, use the company name for animation # define CHENG_IMAGE "cheng.png" # define MAI_IMAGE "mai.png" # define KE_IMAGE "ke.png" # define JI_IMAGE "ji.png" # endif


Create SplashScene. cpp and SplashScene. H files

This H file mainly defines some methods ............................... Const double MOVE_SPLEED = 0.5f; // animation playback speed void moveKeSpriteToLeft (); // define the void moveMaiSpriteToLeft () method for moving the ke.png genie to the left (); // define the method void initMoveSprite () for moving the mai.png genie to the left; // initialize the image method void startMoveSprite (float dt); // start the method void gotoMenuScene (); // After the animation ends, enter the MenuScene scene method void spriteFadeOut (); // The animation gradually disappears ............................... Sprite * mai_Sprite; // main.png image Sprite * ke_Sprite; // ke.png image Sprite * ji_Sprite; // ji.png image Sprite * cheng_Sprite; // cheng.png image Sprite Size visibleSize; // window Size spriteSize; // the Size of each image


The main content of SplashScene. cpp is as follows:


Bool SplashScene: init () {if (! Layer: init () {return false;} visibleSize = Director: getInstance ()-> getVisibleSize (); // initialize the window size variable Vec2 origin = Director :: getInstance ()-> getVisibleOrigin (); initMoveSprite (); // initialize the animation genie method scheduleOnce (schedule_selector (SplashScene: startMoveSprite), ONE_SECOND ); // return true after the animation starts playing for 1 second in the scenario ;}

The initMoveSprite () method is as follows: Call the Sprite: create method to create four genie mai_Sprite = Sprite: create (MAI_IMAGE );.................... SpriteSize = mai_Sprite-> getContentSize (); // assign a value to the animation size. The size of each animation is the same. // Place the sprite image mai_Sprite-> setPosition (ccp (visibleSize. width/2-(2 * spriteSize. width), visibleSize. height/2); ke_Sprite-> setPosition (ccp (visibleSize. width/2-spriteSize. width, visibleSize. height/2); ji_Sprite-> setPosition (ccp (visibleSize. width/2, visibleSize. height/2); cheng_Sprite-> setPosition (ccp (visibleSize. width/2 + spriteSize. width, visibleSize. height/2); set all the genie anchor points to (0, 0.5), so that the four images can be arranged in the center of the window mai_Spr Ite-> setAnchorPoint (ccp (0, 0.5 ));........................ This-> addChild (mai_Sprite); // Add the genie to the scenario


Start playing the animation:


Void SplashScene: startMoveSprite (float dt) {// The animation starts from the right. The last Genie, cheng, first moves the position MoveBy * moveChengToLeft1 = MoveBy :: create (MOVE_SPLEED, ccp (-spriteSize. width, 0); cheng_Sprite-> runAction (moveChengToLeft1); // move the Tianji field from left to right, the two animations are equivalent to the positions MoveBy * moveJiToright = MoveBy: create (MOVE_SPLEED, ccp (spriteSize. width, 0); CallFunc * callFunc = CallFunc: create (CC_CALLBACK_0 (SplashScene: moveKeSpriteToLeft, this); // call the moveKeSpriteToLeft () method after the animation ends, start the animated ji_Sprite of the genie ke-> runAction (Sequence: create (moveJiToright, callFunc, NULL ));}

Genie ke Animation:


Void SplashScene: moveKeSpriteToLeft () {// The genie cheng moves the position MoveBy * moveChengToLeft2 = MoveBy: create (MOVE_SPLEED, ccp (-spriteSize. width, 0); cheng_Sprite-> runAction (moveChengToLeft2); // The sprke moves a position from left to right and switches the position MoveBy * ke_Sprite_MoveBy = MoveBy :: create (MOVE_SPLEED, ccp (spriteSize. width, 0); CallFunc * callFunc2 = CallFunc: create (CC_CALLBACK_0 (SplashScene: moveMaiSpriteToLeft, this); // call moveMaiSpriteToLeft () method after the animation ends, start the animation ke_Sprite-> runAction (Sequence: create (ke_Sprite_MoveBy, callFunc2, NULL) of the genie mai ));}

Genie mai Animation:


Void SplashScene: moveMaiSpriteToLeft () {// The genie cheng moves another position from right to left. MoveBy * moveChengToLeft3 = MoveBy: create (MOVE_SPLEED, ccp (-spriteSize. width, 0); cheng_Sprite-> runAction (moveChengToLeft3); // The genie mai moves a position from left to right, and switches the position MoveBy * mai_Sprite_MoveBy = MoveBy :: create (MOVE_SPLEED, ccp (spriteSize. width, 0); CallFunc * callFunc3 = CallFunc: create (CC_CALLBACK_0 (SplashScene: spriteFadeOut, this); // call the spriteFadeOut () method after the genie mai animation ends, animation mai_Sprite-> runAction (Sequence: create (mai_Sprite_MoveBy, callFunc3, NULL) that begins scene disappearance ));}

Scene disappearance Animation:


Void SplashScene: spriteFadeOut () {// defines four deprecated FadeOut animations. The duration is 2 seconds. FadeOut * fadeOut1 = FadeOut: create (ONE_SECOND * 2 ); fadeOut * fadeOut2 = FadeOut: create (ONE_SECOND * 2); FadeOut * fadeOut3 = FadeOut: create (ONE_SECOND * 2); FadeOut * fadeOut4 = FadeOut :: create (ONE_SECOND * 2); mai_Sprite-> runAction (fadeOut1); ke_Sprite-> runAction (fadeOut2); ji_Sprite-> runAction (fadeOut3); CallFunc * callFunc4 = CallFunc :: create (CC_CALLBACK_0 (SplashScene: gotoMenuScene, this); // call the gotoMenuScene () method after the animation ends to enter the MenuScene scene interface cheng_Sprite-> runAction (Sequence: create, callFunc4, NULL ));}


Go to the scenario method gotoMenuScene () and print only the log temporarily.

Void SplashScene: gotoMenuScene ()

{

Log ("gotoMenuScene ");

Director: getInstance ()-> replaceScene (MenuScene: createScene ());

}

The process is simple, as shown in the following flowchart.



The title animation ends. To be continued ................

Related Article

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.