Cocos2d-x 3.2 Monopoly game project development-Part 1 Toast prompt box, cocos2d-xtoast
When a toll is paid, the number of reduced funds is displayed near the role, and the number of funds added is displayed for the role that receives the toll.
I have made some changes to this information on the Internet.
Write a CocosToast class
#ifndef __CocosToast_H__#define __CocosToast_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;using namespace std;class CocosToast :public LayerColor{public:CocosToast(void);~CocosToast(void);static void createToast(Node* node,const std::string& msg,const float& time,Vec2 point);void removeToast(Node* node);};#endif
# Include "CocosToast. h "parameter node: add the parent node of the Toast layer msg: displayed information time: toast length of time point: toast position coordinate void CocosToast: createToast (cocos2d :: node * node, const std: string & msg, const float & time, Vec2 point) {// create the label auto label = Label: createWithSystemFont (msg. c_str (), "Arial", 20); label-> setColor (Color3B: WHITE); label-> ignoreAnchorPointForPosition (false); label-> setAnchorPoint (Vec2 :: ANCHOR_MIDDLE ); // Toast layer auto layer = LayerColor: create (Color4B (100,100,100,255); layer-> ignoreAnchorPointForPosition (false); layer-> setAnchorPoint (Vec2: ANCHOR_MIDDLE ); layer-> setContentSize (label-> getContentSize () + Size (20, 15); node-> addChild (layer); node-> addChild (label ); layer-> setPosition (point); label-> setPosition (layer-> getPosition (); // The action when toast is displayed, first from bottom to top, return to the point position from top to bottom. When the action ends, clear the toast from the parent node Seq1 = Sequence: create (FadeIn: create (time/5), DelayTime: create (time/5*1.5), FadeOut :: create (time/5*2.5), CallFuncN: create (layer, callfuncN_selector (CocosToast: removeToast), NULL); auto seq2 = Sequence: create (EaseSineIn :: create (MoveBy: create (time/5, Vec2 (0, 50), DelayTime: create (time/5*2), EaseSineOut: create (MoveBy :: create (time/3, Vec2 (0,-50), NULL); auto spawn = Spawn: create (seq1, seq2, NU LL); auto action = Repeat: create (spawn, 1); layer-> setOpacity (0); label-> setOpacity (0); layer-> runAction (action ); label-> runAction (action-> clone ();} void CocosToast: removeToast (Node * node) {this-> removeFromParentAndCleanup (true);} CocosToast :: cocosToast (void) {}cocostoast ::~ CocosToast (void ){}
Modify the payTolls method of GameBaseScene.
Void GameBaseScene: payTolls (int payTag, float x, float y, int playerTag ){............ Switch (playerTag) {case player_second Tag: {int retMoney = displayArea (x, y, player1, middle); refreshMoneyLabel (landOwner, money + retMoney); refreshMoneyLabel (player1, -(money + retMoney); // Toast displays the number of funds added and reduced by the corresponding role. CocosToast: createToast (this, String: createWithFormat ("+ % d ", money + retMoney)-> getCString (), TOAST_SHOW_TIME, landOwner-> GetPosition (); CocosToast: createToast (this, String: createWithFormat ("-% d", money + retMoney)-> getCString (), TOAST_SHOW_TIME, player1-> getPosition (); // note that when the first role is used, the TOAST_SHOW_TIME will be delayed and the next walking message will be sent to avoid the toast display being too frequent scheduleOnce (schedule_selector (GameBaseScene ), TOAST_SHOW_TIME); break;} case PLAYER_2_TAG: {int retMoney = displayArea (x, y, player2, player1_building_1_tiledID, player1_buildi Ng_2_tiledID, region); refreshMoneyLabel (landOwner, money + retMoney); refreshMoneyLabel (player2,-(money + retMoney); CocosToast: createToast (this, String :: createWithFormat ("+ % d", money + retMoney)-> getCString (), TOAST_SHOW_TIME, landOwner-> getPosition (); CocosToast: createToast (this, String :: createWithFormat ("-% d", money + retMoney)-> getCString (), TOAST_SHOW_TIME, player2-> getPosi Tion (); icationcenter center: getInstance ()-> postNotification (MSG_PICKONE_TOGO, String: createWithFormat ("% d", MSG_PICKONE_TOGO_TAG); break ;}} ...................}
Click to download the code
Http://download.csdn.net/detail/lideguo1979/8334883
To be continued ...................