zoukankan      html  css  js  c++  java
  • toast提示框的实现

    Toast.h文件

    #ifndef Toast_h__
    #define Toast_h__
    #include "cocos2d.h" 
    #include "cocos-ext.h" 
    #include "ui/CocosGUI.h" 
    USING_NS_CC; 
    USING_NS_CC_EXT; 
    using namespace ui; 
    class Toast : public LayerColor { 
    public:  static void makeText(Node* node,const std::string& msg,const float& time);//静态函数,方便类直接调用 
    		 void removeToast(Node* node); };
    
    #endif // XYToast_h__
    

    Toast.cpp文件

    #include "Toast.h"
    void Toast::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)); 
    ly->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2+100));
    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 seq1=CCSequence::create(CCFadeIn::create(time / 5),
    		CCDelayTime::create(time / 5 * 3), CCFadeOut::create(time / 5), CallFuncN::create(ly, callfuncN_selector(Toast::removeToast)), nullptr);
    auto spawn = Spawn::create(seq1, nullptr); 
    
    auto action = Repeat::create(spawn, 1);
    ly->setOpacity(0);
    
    pLabel->setOpacity(0);
    
    ly->runAction(action);
    
    
    pLabel->runAction(action->clone());
    
    }
    
    
    void Toast::removeToast(Node* node) {
    	log("node = %s", node->getDescription().c_str()); 
    this->removeFromParentAndCleanup(true);
    }

    调用代码:Toast::makeText(this, "Toast!", 2.5f);


  • 相关阅读:
    Android应用程序组件Content Provider简要介绍和学习计划
    本人其它博客
    Android应用程序组件Content Provider的启动过程源代码分析
    Android应用程序组件Content Provider应用实例
    Team Foundation Server 2010 Performance Tuning – Lessons learned
    Katapult:KDE 桌面辅佐序次
    Informix IDS 11系统打点(918考试)认证指南,第2局部系统活动监督(3)
    Amarok 1.4.6
    Informix IDS 11琐细管理(918测验)认证指南,第1部分IDS安设和设置(1)
    KTorrent 2.2 公布
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091804.html
Copyright © 2011-2022 走看看