Cocos2d-x 3.2 Monopoly Game development-part 17th toast Prompt box

Source: Internet
Author: User
Tags addchild

In the payment of tolls, the number of reduced funds is shown near the role, the role of receiving tolls shows the number of increased funds, the effect



There are a lot of information on the Internet, I have a slightly modified

Write a cocostoast Toast Class

#ifndef __cocostoast_h__#define __cocostoast_h__#include "cocos2d.h" #include "cocos-ext.h" using_ns_cc;using namespace Std;class cocostoast:p ublic 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 the "CocosToast.h" parameter node: Add the parent node of the Toast Layer msg: The information displayed time:toast the length of time displayed point:toast the position coordinates void Cocostoast:: Createtoast (Cocos2d::node *node, const std::string &msg, const float &TIME,VEC2 point) {//Create display information for label Auto L    Abel = Label::createwithsystemfont (Msg.c_str (), "Arial", 20);    Label->setcolor (Color3b::white);    Label->ignoreanchorpointforposition (FALSE);       Label->setanchorpoint (Vec2::anchor_middle);    Layer Auto layer of toast = 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 of the toast display, first from the bottom up, then up and down, back to point position, the end of the action, the toast from the parent node clear Auto 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, NULL);    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) {}

Now modify the Paytolls method of gamebasescene


void Gamebasescene::p aytolls (int paytag,float x,float y, int playertag) {.... switch (playertag) {case Player_1_tag: {i NT Retmoney = Displayarea (x,y,player1,player2_building_1_tiledid,player2_building_2_tiledid,player2_building_3_    Tiledid);    Refreshmoneylabel (Landowner,money + Retmoney);   Refreshmoneylabel (player1,-(Money + Retmoney)); Toast shows the number of increases and decreases in 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 it is the first role, the delay toast_show_time seconds after sending the continue walk message, avoiding the toast display too frequently scheduleonce (Schedule_selector (gamebasescene::   Sendmsgpickonetogo), toast_show_time);  Break } case Player_2_tag: {int retmoney = Displayarea (X,y,player2,player1_building_1_tiledid,player1_building_2_tiledid,    Player1_building_3_tiledid); 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->getposition ()); Notificationcenter::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 ....... .......

Cocos2d-x 3.2 Monopoly Game development-part 17th toast Prompt box

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.