Cocos2d-x 3.2 Monopoly game project development-Part 2 improve the role walking experience, cocos2d-x Project Development

Source: Internet
Author: User

Cocos2d-x 3.2 Monopoly game project development-Part 2 improve the role walking experience, cocos2d-x Project Development

Before obtaining the number of random steps, a friendly prompt should be provided to the player indicating which role to start walking. A few steps are required.

In this way, let the role flash before walking, and mark the path to be taken by the role in a special color. The effect is as follows:



First, implement the role flashing: The flashing is related to the role. Therefore, it is most appropriate to modify it in the startGo method of the RicherPlayer class.

VoidRicherPlayer: startGo (std: vector <int> rowVector, std: vector <int> colVector) {// creates a fade-in and fade-out action for the role to run. After the action ends, call startRealGo to start walking. Here the closure function is used to simplify the code FadeOut * fadeout = FadeOut: create (0.2); FadeIn * fadein = FadeIn: create (0.2); this-> runAction (Sequence :: create (fadeout, fadein, CallFunc: create ([rowVector, colVector, this] () {RicherGameController * instance = RicherGameController: getInstance (); instance-> startRealGo (rowVector, colVector, this) ;}, NULL) ;}</span>

Next, we start to color the path. We will use six sprite to add these six sprite to the Vector. Each time, based on the number of walking steps, we will retrieve the sprite from the vector and place it in the path, set the visible attribute of the sprite to false invisible after the path is completed each time. The logic is clear and the code is easy to write.

The GameBaseScene. h header file is as follows:

Class GameBaseScene: public Layer {public :.................... Static Vector <Sprite *> pathMarkVector; // defines the Vector used to store 6 paths to block the genie static void drawPathColor (std: vector <int> rowVector, std :: vector <int> colVector); // draw the path occlusion method private: void addPathMark (); // define the method for adding the occlusion genie .........................}


Cpp File
Bool GameBaseScene: init (){.................... // Before adding a role, you must prevent the role from being blocked by addPathMark (); addPlayer ();.......................... Return true ;}

Implement the addPathMark method in GameBaseScene. cpp.

Void GameBaseScene: addPathMark () {// This method creates Six Paths to block Sprite and add it to the current scenario Sprite * mark1 = Sprite: create (PATH_MARK_1 ); sprite * mark2 = Sprite: create (PATH_MARK_2); Sprite * mark3 = Sprite: create (PATH_MARK_3); Sprite * mark4 = Sprite: create (PATH_MARK_4 ); sprite * mark5 = Sprite: create (PATH_MARK_5); Sprite * mark6 = Sprite: create (PATH_MARK_6); mark1-> setAnchorPoint (ccp (0, 0 )); mark2-> setAnchorPoint (ccp (0, 0); mark3-> setAnchorPoint (ccp (0, 0); mark4-> setAnchorPoint (ccp (0, 0 )); mark5-> setAnchorPoint (ccp (); mark6-> setAnchorPoint (ccp (); // All are invisible mark1-> setVisible (false ); mark2-> setVisible (false); mark3-> setVisible (false); mark4-> setVisible (false); mark5-> setVisible (false); mark6-> setVisible (false ); addChild (mark1); addChild (mark2); addChild (mark3); addChild (mark4); addChild (mark5); addChild (mark6); pathMarkVector. pushBack (mark1); pathMarkVector. pushBack (mark2); pathMarkVector. pushBack (mark3); pathMarkVector. pushBack (mark4); pathMarkVector. pushBack (mark5); pathMarkVector. pushBack (mark6 );}

// Draw path occlusion method void GameBaseScene: drawPathColor (std: vector <int> rowVector, std: vector <int> colVector) {// obtain the number of occlusion to be drawn, because the position 0 in the path array is the current position of the role, we should not block int stepsCount = rowVector. size ()-1; // extract the Sprite from the occlusion container, place it in the corresponding position, and set it to visible for (int I = 1; I <rowVector. size (); I ++) {pathMarkVector. at (I-1)-> setPosition (ccp (colVector [I] * 32, rowVector [I] * 32); pathMarkVector. at (I-1)-> setVisible (true );}}

In the RicherPlayer: startGo method, draw the path occlusion effect void RicherPlayer: startGo (std: vector <int> rowVector, std: vector <int> colVector) before you actually start walking) {// Blink * blink = Blink: create (0.5, 1); FadeOut * fadeout = FadeOut: create (0.2); FadeIn * fadein = FadeIn :: create (0.2); // draw the path occlusion effect GameBaseScene: drawPathColor (rowVector, colVector); this-> runAction (Sequence: create (fadeout, fadein, CallFunc :: create ([rowVector, colVector, this] () {RicherGameController * instance = RicherGameController: getInstance (); instance-> startRealGo (rowVector, colVector, this );}), NULL ));}

Void RicherGameController: endGo () {// after each move, set the occlusion effect of the current path to invisible, so that each step is taken, effect of path occlusion disappearance: pathMarkVector. at (steasgone)-> setVisible (false); steasgone ++ ;.................. Log ("go end ");}

Click to download code http://download.csdn.net/detail/lideguo1979/8305165


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.