Cocos2d-x 3.2 Monopoly game project development-Part 1 buy space animation, cocos2d-x Project Development

Source: Internet
Author: User
Tags addchild

Cocos2d-x 3.2 Monopoly game project development-Part 1 buy space animation, cocos2d-x Project Development

When purchasing an open space, we add an animation:

The animation consists of two parts. The first part is to increase the footprint from small to small, and then from large to small. The second part is to play a particle effect after the footprint decreases.

First download particle editing tool: Cocos2d-x-ParticleEditor this is an open source free tool:

Https://github.com/chaseli/Cocos2d-x-ParticleEditor-for-Windows

 

The enable tool of particle editor.exe under the bin directory contains particle instances. We can select some particle effects for our use, or edit the effects by ourselves. In short, it is very convenient to use this tool to edit particles. You can modify the data on the right side and view the results.

 

Let's start to modify our code and add action and particle effects.

1. First, modify the RicherGameController code.

<Span style = "color: #333333;"> void RicherGameController: endGo () {GameBaseScene: pathMarkVector. at (steasgone)-> setVisible (false); steasgone ++; if (steasgone> = stepsCount) {// After the role is completed, the handlePropEvent method is called, handlePropEvent (); return;} currentRow = nextRow; currentCol = nextCol; moveOneStep (_ richerPlayer); log ("go end") ;}</span>

<Span style = "color: #333333;"> void RicherGameController: handlePropEvent (){................................. For (int I = 0; I <4; I ++) {Point ptMap = Util: GL2map (Vec2 (positionAroundEnd [I] [0], positionAroundEnd [I] [1]), GameBaseScene: _ map); int titleId = GameBaseScene: landLayer-> getTileGIDAt (ptMap); if (titleId = GameBaseScene: Signature) {.............................. // Here, the role tag is sent from the message String * str = String: createWithFormat ("% d-% f-% d", msg_buy_blk_tag, x, y, _ richerPlayer-> getTag (); icationcenter center: getInstance ()-> postNotification (MSG_BUY, str); break ;}}</span>

2. Modify the GameBaseScene. cpp file.

<Span style = "color: #333333;"> This method is mainly used to load the footprint genie related to the action, so that void GameBaseScene: doSomeForParticle () {scaleby1ForBuyLand = ScaleBy:: create (0.1, 1.5); scaleby2ForBuyLand = ScaleBy: create (0.5, 0.7); scaleby1ForBuyLand-> retain (); scaleby2ForBuyLand-> retain (); foot1Sprite = Sprite :: create (playereffectle_png); addChild (foot1Sprite); foot1Sprite-> setAnchorPoint (ccp (0, 0); foot2Sprite = Sprite: create (CROP); addChild (foot2Sprite ); foot2Sprite-> setAnchorPoint (ccp (0, 0) ;}</span>

<Span style = "color: #333333;"> GameBaseScene. in cpp, the receivedNotificationOMsg method processes void GameBaseScene: receivedNotificationOMsg (Object * data ){.............................. Case MSG_BUY_BLANK_TAG: {buy_land_x = messageVector. at (1)-> floatValue (); buy_land_y = messageVector. at (2)-> floatValue (); int playerTag = messageVector. at (3)-> intValue (); // when receiving a message from the previous RicherGameController for purchasing an empty plot, handle the switch (playerTag) {case player_tags tag respectively based on the role: // call the showBuyLandDialog method when it is the main character. The pop-up dialog box is handled manually {showBuyLandDialog (msg_buy_blk_tag); break;} case PLAYER_2_TAG: // when it is the second role, no dialog box is displayed, directly buy land, run the animation, and play the particle effect {Point pointOfGL = Util: map2GL (ccp (buy_land_x, buy_land_y), GameBaseScene: _ map); foot2Sprite-> setVisible (true ); foot2Sprite-> setPosition (pointOfGL); Point pointOfMap = ccp (buy_land_x, buy_land_y); foot2Sprite-> runAction (Sequence: create (Sequence, scaleby2ForBuyLand, </span>
<span style="color:#333333;"><span style="white-space:pre"></span>CallFunc::create([this,pointOfMap,pointOfGL](){playParticle(pointOfGL,PLAYER2_1_PARTICLE_PLIST);foot2Sprite->setVisible(false);landLayer->setTileGID(player2_building_1_tiledID,ccp(buy_land_x,buy_land_y));NotificationCenter::getInstance()->postNotification(MSG_PICKONE_TOGO,String:<span style="white-space:pre"></span>:createWithFormat("%d",MSG_PICKONE_TOGO_TAG));}),NULL));break;}}break;}…………………………………..}}</span>

3,

Next, let's see the execution of the actions after the protagonist (manual) clicks the OK button in the dialog box.

<Span style = "color: #333333;"> void GameBaseScene: buyLandCallback (Node * pNode) {if (pNode-> getTag () = Btn_ OK _TAG) {switch (popDialog-> getDataTag () {case msg_buy_blk_tag: {// when you click the confirm button for purchasing a blank block, first, convert the land plot coordinate to the GL coordinate Point pointOfGL = Util: map2GL (ccp (buy_land_x, buy_land_y), GameBaseScene: _ map); foot1Sprite-> setVisible (true ); foot1Sprite-> setPosition (pointOfGL); Point pointOfMap = ccp (buy_land_x, buy_land_y); // enables the foot image to be scaled in and out sequentially, and then calls the playParticle method, play the particle effect foot1Sprite-> runAction (Sequence: create (scaleby1ForBuyLand, scaleby2ForBuyLand, </span>
<Span style = "color: #333333;"> <span style = "white-space: pre"> </span> CallFunc: create ([this, pointOfMap, pointOfGL] () {playParticle (pointOfGL, player1_particle particle _ plist); // hide the foot image, set the gid of land's Title, and change it to foot graph block foot1Sprite-> setVisible (false ); landLayer-> setTileGID (player1_building_1_tiledID, pointOfMap) ;}, NULL); log ("need $1000"); break;} case MSG_BUY_LAND_1_TAG: ..........................} PopDialog-> setVisible (false); // after 1 second, send a message so that other roles can walk this-> scheduleOnce (schedule_selector (GameBaseScene: sendMSGPickOneToGO), 1.0f ); log ("Btn_ OK _TAG ");}..........................................} </Span>
<Span style = "color: #333333;"> // The Particle playback method is to load the plist file of the particle, add it, and release it after the playback is complete. Void GameBaseScene: playParticle (Point point, char * plistName) {participant system * metadata = participant systemquad: create (plistName); queue-> retain (); participant batchnode * batch = participant batchnode :: createWithTexture (participant system_foot-> getTexture (); batch-> addChild (participant system_foot); addChild (batch); participant system_foot-> setPosition (point + ccp (tiledWidth/2, tiledHeight/2); participant system_foot-> release () ;}</span>

Effect


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


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

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.