#include "cocos2d.h"
using namespace cocos2d;
USING_NS_CC;
using namespace std;
class Toast: public LayerColor
{
public:
Size winSize;
Vec2 winOrigin;
// CCSize visibleSize;
// CCPoint origin;
//CCScale9Sprite* bg;
Sprite *bg;
public:
Toast();
~Toast();
void removeSelf();
virtual bool init();
void initToast(string msg,float time);
CREATE_FUNC(Toast);
void onExit();
};
//////////////////////////////////////////////////////////////////////////
//建立通用彈跳視窗
//參考http://www.android100.net/html/201406/04/18200.html
Toast::Toast()
{
}
Toast::~Toast()
{
}
bool Toast::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!LayerColor::initWithColor(Color4B(0, 0, 0, 0)));//ccc4(0, 0, 0, 125)
winSize = Director::getInstance()->getVisibleSize();
winOrigin = Director::getInstance()->getVisibleOrigin();
//====================================
bg = Sprite::createWithSpriteFrameName(S_MSGBOX_BK);
//bg = CCScale9Sprite::createWithSpriteFrameName(S_BTN_BACKGROUNP);
bg->setPosition(Vec2(winOrigin.x+winSize.width/2,winOrigin.y+130*winSize.height/1080));
//============================
bRet = true;
} while (0);
return bRet;
}
void Toast::onExit()
{
LayerColor::onExit();
}
void Toast::initToast( string msg,float time )
{
auto pLabel = Label::createWithSystemFont(msg.c_str(), S_FONE, *pSTR_TOAST_SIZE);
pLabel->setColor(COLOR_STRING_BLACK);
Size tSizeOrig=bg->getContentSize();
Size tTargetSize=pLabel->getContentSize();
//bg->setContentSize(CCSizeMake(pLabel->getContentSize().width+10,pLabel->getContentSize().height+10));
bg->setScaleX( ( tTargetSize.width / tSizeOrig.width )); //利用CCSPRITE 需額外進行縮放
bg->setScaleY( ( tTargetSize.height / tSizeOrig.height)); //利用CCSPRITE 需額外進行縮放
bg->setColor(Color3B(240,240,240));
bg->addChild(pLabel, 1);
this->addChild(bg,10);
pLabel->setPosition(bg->getContentSize()/2);
pLabel->setScaleX( ( tSizeOrig.width /tTargetSize.width )); //利用CCSPRITE 需額外進行縮放
pLabel->setScaleY( ( tSizeOrig.height/ tTargetSize.height )); //利用CCSPRITE 需額外進行縮放
pLabel->runAction(Sequence::create(FadeIn::create(time/5),
DelayTime::create(time/5*3),FadeOut::create(time/5),NULL));
bg->runAction(Sequence::create(FadeIn::create(time/5),
DelayTime::create(time/5*3),FadeOut::create(time/5),
//CallFunc::create(this,callfunc_selector(Toast::removeSelf)),NULL));
CallFunc::create(CC_CALLBACK_0(Toast::removeSelf, this)),NULL));
//=========================
//this->scheduleOnce(schedule_selector(XYToast::removeSelf),time);
}
void Toast::removeSelf()
{
this->removeFromParentAndCleanup(true);
}
訂閱:
張貼留言 (Atom)
cocos2dx-lua 建立滑鼠監聽
重要關鍵字 EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority if IsPc() then --建立滑鼠監聽 local listener = cc.EventListenerMouse...
-
http://blog.csdn.net/teng_ontheway/article/details/26078869 遊戲中經常會用到一些變換: 遊戲中武器和角色在一個layer上,為了效率,會考慮將bullet, effect和 PhysicsParticle分別放...
-
AppDelegate::applicationDidFinishLaunching()函數里 把 glview = GLViewImpl::createWithRect("NAME", Rect(0, 0, designResolutionSize.widt...
-
https://cocosgamestory.wordpress.com/2015/08/12/%E6%9B%B4%E6%8F%9B%E6%96%B0%E7%9A%84appicon/ 使用心得: 透過網站 取得各種SIZE的ICON,在手動更換目錄下的ICON即可 (coco...
沒有留言:
張貼留言