Cocos2d-x implementing the Toast feature of Android

Source: Internet
Author: User

1. Toast
The Android toast is a view that quickly displays a small amount of information to the user. Mainly used for some hints and help. This paper realizes the most basic operation of toast,
The code is as follows:
Pactoast.h#include "Cocos2d.h" #include "cocos-ext.h" #include "ui/cocosgui.h" USING_NS_CC; Using_ns_cc_ext;using namespace Ui;class pactoast:public layercolor{public:        static void Maketext (node* node,const std::string& msg,const float& time);//static function, convenient class directly call    void Removetoast (node* Node);};

Pactoast#include "PacToast.h" void Pactoast::maketext (Cocos2d::node *node, const std::string &msg, const float    &time) {Size visiblesize = director::getinstance ()->getvisiblesize ();    VEC2 origin = Director::getinstance ()->getvisibleorigin ();    Auto Plabel = Label::createwithsystemfont (Msg.c_str (), "Arial", 30);    Plabel->setcolor (Color3b::white);    Plabel->ignoreanchorpointforposition (FALSE);        Plabel->setanchorpoint (Vec2::anchor_middle);    Auto ly = Layercolor::create (color4b (130,120,120,255));    Ly->ignoreanchorpointforposition (FALSE);    Ly->setanchorpoint (Vec2::anchor_middle);    Ly->setcontentsize (plabel->getcontentsize () + Size (20,15));    Node->addchild (ly);    Node->addchild (Plabel);    Ly->setposition (VEC2 (Visiblesize.width/2,-plabel->getcontentsize (). height));    Plabel->setposition (Ly->getposition ()); Auto seq1 = Sequence::create (Fadein::create (TIME/5), Delaytime::create (time/5*1.5), Fadeout::create (TIME/5*2.5), Callfuncn::create (Ly,callfuncn_selector (Pactoast::removetoast)), nullptr); Auto SEQ2 = Sequence::create (Easesinein::create (Moveby::create (TIME/5, VEC2 (0,200))), Delaytime::create (time/5*2),    Easesineout::create (Moveby::create (TIME/3, VEC2 (0,-200))), nullptr);    Auto spawn = Spawn::create (seq1, SEQ2, nullptr);    Auto action = repeat::create (spawn,1);    Ly->setopacity (0);    Plabel->setopacity (0);    Ly->runaction (action); Plabel->runaction (Action->clone ());}    void Pactoast::removetoast (node* node) {log ("node =%s", Node->getdescription (). C_STR ()); This->removefromparentandcleanup (TRUE);}

2. Using Code
void Helloworld::menuclosecallback (ref* psender) {#if (Cc_target_platform = = CC_PLATFORM_WP8) | | (Cc_target_platform = = CC_PLATFORM_WINRT) MessageBox ("You pressed the Close button. Windows Store Apps do not implement a close button. "," Alert ");    return; #endif # if (cc_target_platform = = Cc_platform_ios)    Pactoast::maketext (this, "I am toast! ", 2.5f);    #endif}



Cocos2d-x implementing the Toast feature of Android

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.