Cocos2d-x 自制提示框(就是游戏登陆失败之类的提示一下消失效果)

来源:互联网 发布:coc城墙升级数据 编辑:程序博客网 时间:2024/05/20 10:53


用法简单 直接create就OK了,不用添加在layer上的,感觉改成静态方法会更好的,暂时就这样先吧,静态有空在改。


直接代码了,没啥好讲的


.h文件

#pragma once#include "cocos2d.h"USING_NS_CC;class HintBox : public CCLayerColor{public:HintBox(void);~HintBox(void);static HintBox* createBox(const char* content = "NULL", const ccColor4B& color = ccc4(200,200,200,200), float width = 400.0f, float high = 100.0f);virtual bool init(const char* content, const ccColor4B& color, float width, float high);virtual void onEnter();virtual void onExit();void deleteLayer(CCNode* obj);};

.cpp 文件


#include "HintBox.h"HintBox::HintBox(void){}HintBox::~HintBox(void){}HintBox* HintBox::createBox(const char* content, const ccColor4B& color, float width, float high){HintBox* box = new HintBox();if(box && box->init(content, color, width, high)){return box;}return NULL;}bool HintBox::init(const char* content, const ccColor4B& color, float width, float high){CCLayerColor::initWithColor(color);CCSize size = CCDirector::sharedDirector()->getWinSize();this->setContentSize(CCSize(width, high));CCLabelTTF* ttf = CCLabelTTF::create(content, "黑体", 30);this->addChild(ttf);ttf->setPosition(ccp(width/2, high/2));CCDirector::sharedDirector()->getRunningScene()->addChild(this, 100);this->setPosition(ccp(size.width/2-width/2, size.height/2));return true;}void HintBox::onEnter(){CCLayerColor::onEnter();this->runAction(CCSequence::create( CCMoveBy::create(0.8f,ccp(0,50)), CCCallFuncN::create(this,callfuncN_selector(HintBox::deleteLayer)), NULL ));}void HintBox::onExit(){CCLayerColor::onExit();}void HintBox::deleteLayer(CCNode* obj){this->removeFromParent();}


0 0
原创粉丝点击