Cocos2d-x 3.2 Monopoly Game project development-part 11th promotion of character walking experience

Source: Internet
Author: User
Tags addchild

A character needs to be friendly when it gets a random number of steps to start walking and take a few steps.

So let's get the character to flash before we walk, and mark the path of the character to go in a special color. The effect is as follows



First, the role flashing: flashing is role-related, so we in the Richerplayer class Startgo method to modify the most appropriate

Voidricherplayer::startgo (Std::vector<int>rowvector,std::vector<int>colvector) {//Create a fade action, let the character run, After the action is over, call Startrealgo to start walking. The closure function is used here 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>

The next step begins to color the path, we use 6 sprite to do, the 6 sprite into the vector, each time according to the number of steps to walk, remove the sprite from the vector, placed in the path position, each time the path is completed, Setting the Visible property of the sprite to false is not visible. The logic is clear and the code is simple to write.

The GameBaseScene.h header files are as follows:

Class Gamebasescene:public Layer{public:            .... static vector<sprite*> pathmarkvector;//define Vector (....). Used to store 6 path occlusion Wizard static void Drawpathcolor (std::vector<int> rowvector,std::vector<int> colvector);// Draw the path Occlusion method private:       void Addpathmark ();//define the method to add the Occlusion Wizard .....       ... ...}


CPP File
BOOL Gamebasescene::init () {......... .....//The method of adding occlusion must prevent the role from being obscured by Addpathmark (), Addplayer (), ..., and so on, before adding a role method. ..... return. true;}

Implement this Addpathmark method in GameBaseScene.cpp

void Gamebasescene::addpathmark () {//This method is to create a 6 path occlusion Sprite and add it to the current scene 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 (0,0)); Mark6->setanchorpoint (CCP (0,0));//Both 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);p athmarkvector.pushback (MARK2);p athmarkvector.pushback (MARK3); Pathmarkvector.pushback (MARK4);p athmarkvector.pushback (mark5);p athmarkvector.pushback (MARK6);}

Draw path occlusion method void Gamebasescene::d rawpathcolor (std::vector<int> rowvector,std::vector<int> colVector) {// Gets the number of occlusion to draw because the position of the path array 0 is the current position of the role and should not be drawn as occlusion int stepscount = Rowvector.size ()-1; Remove the occlusion 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));p athmarkvector.at (i-1)->setvisible (True);}}

In the Richerplayer::startgo method, before actually starting to walk, draw the path occlusion effect void Richerplayer::startgo (std::vector<int> rowvector,std:: Vector<int> colvector) {//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::d rawpathcolor (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 () {//At the end of each move, the current path occlusion effect is set to not be visible, so that each step is completed, and the current path occlusion disappears as a result of Gamebasescene:: pathmarkvector.at (Stephasgone)->setvisible (false); Stephasgone++;..................log ("Go End");}

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


To be continued ........ ...........

Cocos2d-x 3.2 Monopoly Game project development-part 11th promotion of character walking experience

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.