In the lower right corner, show the number of rounds in the game:
Implementation method:
1. Create a frame buffer in the Gamebasescene class to hold 10 numbers of spriteframe, representing 0-9 of the Arabic numerals, into the vector
2. Define the variable Gameroundcount in the Gamebasescene class with an initial value of 0
3. Define the Refreshrounddisplay () method in the Gamebasescene class to refresh the turn display
Implementation mode, the use of digital modulus, divided by 0 is not zero, until taken, from the Digitevector to obtain the sprite object, reverse into the refreshroundvector, after the completion of the mold, refresh display
4, when all characters go through the gameroundcount++, then call Refreshrounddisplay () refresh the display
Here's a look at the code implementation
1, according to the digital plist file in the frame cache to store the digital spriteframe, while depositing into the Digiteroundvector container void Gamebasescene::adddigiteroundsprite () {//2, Define the variable gameroundcount, the initial value is 0, record the number of rounds played by the game Gameroundcount=0;auto Framecache = Spriteframecache::getinstance (); Framecache->addspriteframeswithfile ("Map/digital_round.plist");d Igiteroundvector.pushback (frameCache-> Getspriteframebyname (DIGITAL_0));d Igiteroundvector.pushback (Framecache->getspriteframebyname (DIGITAL_1)); Digiteroundvector.pushback (Framecache->getspriteframebyname (digital_2));d Igiteroundvector.pushback ( Framecache->getspriteframebyname (digital_3));d Igiteroundvector.pushback (framecache->getspriteframebyname (Digital_4)); Digiteroundvector.pushback (Framecache->getspriteframebyname (digital_5));d Igiteroundvector.pushback ( Framecache->getspriteframebyname (digital_6));d Igiteroundvector.pushback (framecache->getspriteframebyname (digital_7)); Digiteroundvector.pushback (Framecache->getspriteframebyname (digital_8));d Igiteroundvector.pushback ( Framecache->getSpriteframebyname (Digital_9));}
3, Refreshrounddisplay () method, used to refresh the turn display void Gamebasescene::refreshrounddisplay () {// The Refreshroundvector container holds the sprite associated with the number of rounds before it is flushed, so the previous purge is cleared for (auto it = Refreshroundvector.begin (); it! = Refreshroundvector.end (); it++) {((sprite*) *it)->setvisible (false);} Refreshroundvector.clear (); int count = Gameroundcount; Sprite* st;//When the game starts, show the number of rounds as 0 if (count ==0) {st = sprite::createwithspriteframe (digiteroundvector.at (0)); AddChild (ST); Refreshroundvector.pushback (ST);} Convert the number into a Sprite stored in the Refreshroundvector container while (count!=0) {st = Sprite::createwithspriteframe (digiteroundvector.at ( COUNT%10)); AddChild (ST); Refreshroundvector.pushback (st); count = COUNT/10;} Storage due to modulus calculation, are stored in reverse order, so the correct display should be reversed refreshroundvector.reverse (); for (int i = 0;i< refreshroundvector.size (); i++) { Sprite * sp = refreshroundvector.at (i); Sp->setposition (CCP ((tablestartposition_x+50) + (i*25), ());sp-> SetVisible (True);}}
4. When all characters walk through, gameroundcount++, then call Refreshrounddisplay () refresh to show that we handle this logic void Gamebasescene when we receive a request to display the Go button: Receivedmsgforgo (object* data) {if (Retmsgtype ==1) {... dicesprite->resume (); gameroundcount++ (); Refreshrounddisplay ();} ..........................}
Click Download code http://download.csdn.net/detail/lideguo1979/8307969
To be continued ........ .......
Cocos2d-x 3.2 Monopoly Game project development-part 12th shows the turn counter