Cocos2d-x 自制提示框(就是游戏登陆失败之类的提示一下消失效果)
2014-05-06 17:37
204 查看
用法简单 直接create就OK了,不用添加在layer上的,感觉改成静态方法会更好的,暂时就这样先吧,静态有空在改。
直接代码了,没啥好讲的
.h文件
.cpp 文件
直接代码了,没啥好讲的
.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(); }
相关文章推荐
- cocos2d-x 3.0 游戏关卡滑动 弹动 不会出现黑边效果
- win7 打开共享目录提示 —— 登陆失败:未知的用户名或密码错误解决办法
- JS实现输入框提示文字点击时消失效果
- cocos2d-x-3.0rc1 学习笔记2( 什么标题、菜单按钮、粒子效果之类的)
- Ubuntu skype 登陆 提示错误:加载数据库失败
- 【cocos2d-x IOS游戏开发-捕鱼达人16】炮弹攻击效果2
- 【cocos2d-x IOS游戏开发-城市跑酷13】游戏玩法:友情提示:how to play?
- 【Cocos2d-x游戏引擎开发笔记(9)】实现DotA的技能冷却效果
- sql server启动时提示由于登陆失败无法启动服务
- 解决远程桌面连接时闪一下消失不出现登陆界面的问题
- 简单的邮箱登陆的提示效果类似于yahoo邮箱
- 【Cocos2d-x游戏引擎开发笔记(11)】粒子系统----实现下雪效果
- ext4.1 添加滚动提示框(自动消失,冒泡效果)停顿几秒后消失
- 仿新浪微博登陆邮箱提示效果!
- 【Cocos2D-X游戏开发笔记2】自定义场景及场景切换效果
- 仿Discuz!的论坛评分发帖弹出提示并渐渐消失的效果
- Windows7在访问网络共享文件夹提示“登陆失败:未知的用户名或密码错误”
- 解决Xcode 6 beta 编译Cocos2d-x iOS项目失败 在Xcode 6 里编译 iOS项目时可能会失败,提示如下错误: Undefined symbols
- 【Cocos2d-x游戏引擎开发笔记(11)】粒子系统----实现下雪效果
- 【cocos2d-x IOS游戏开发-捕鱼达人12】鱼群效果