Cocos2d-x 3.2 Monopoly game project development-Part 1 show round counter, cocos2d-x Project Development

Source: Internet
Author: User
Tags rounds

Cocos2d-x 3.2 Monopoly game project development-Part 1 show round counter, cocos2d-x Project Development

The number of game rounds is displayed in the lower right corner:

Implementation Method:

1. Create a frame cache in the GameBaseScene class to store SpriteFrame with ten digits, representing 0-9 Arabic numerals and placing them in a Vector.

2. Define the variable gameRoundCount in the GameBaseScene class. The initial value is 0.

3. Define the refreshRoundDisplay () method in the GameBaseScene class to refresh the round display.

Implementation Method: Use the number modulo. Divide the number by 0 and the value is not zero until the result is obtained. Get the sprite object from digiteVector and put it in refreshRoundVector in reverse order. After the modulo is completed, refresh the display.

4. After all the roles are completed, gameRoundCount ++ calls refreshRoundDisplay () to refresh the display.

See the code implementation below


// 1. The digital spriteFrame is stored in the frame cache based on the digital plist file and stored in the digiteRoundVector container void GameBaseScene: addDigiteRoundSprite () {// 2. The variable gameRoundCount is defined, the initial value is 0, and the number of game rounds is recorded. gameRoundCount = 0; auto frameCache = SpriteFrameCache: getInstance (); frameCache-> Merge ("map/digital_round.plist. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_0); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_1); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_2); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_3); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_4); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_5); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_6); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_7); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_8); digiteRoundVector. pushBack (frameCache-> getSpriteFrameByName (DIGITAL_9 ));}

3. refreshRoundDisplay () method, which is used to refresh the void GameBaseScene: refreshRoundDisplay () {// The Sprite related to the number of rounds in the refreshRoundVector container, therefore, we need to clear the previous for (auto it = refreshRoundVector. begin (); it! = RefreshRoundVector. end (); it ++) {(Sprite *) * it)-> setVisible (false);} refreshRoundVector. clear (); int count = gameRoundCount; Sprite * st; // when the game starts, the number of returns is 0 if (count = 0) {st = Sprite :: createWithSpriteFrame (digiteRoundVector. at (0); addChild (st); refreshRoundVector. pushBack (st);} // convert the number to Sprite and store it in the refreshRoundVector container while (count! = 0) {st = Sprite: createWithSpriteFrame (digiteRoundVector. at (count % 10); addChild (st); refreshRoundVector. pushBack (st); count = count/10;} // during storage, the modulo computation is stored in reverse order. Therefore, when correctly displaying the information, you must reverse the order to refreshRoundVector. reverse (); for (int I = 0; I <refreshRoundVector. size (); I ++) {Sprite * sp = refreshRoundVector. at (I); sp-> setPosition (ccp (tableStartPosition_x + 50) + (I * 25), 50); sp-> setVisible (true );}}

4. After all the roles are completed, gameRoundCount ++ calls refreshRoundDisplay () to refresh and display the logic void GameBaseScene :: receivedMsgForGo (Object * data) {if (retMsgType = 1 ){............... DiceSprite-> resume (); gameRoundCount ++; refreshRoundDisplay ();}..........................}



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


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.