Files
wnmj-normal/Classes/GameFrame/NoticeMsg.cpp

65 lines
1.4 KiB
C++
Raw Normal View History

2026-03-03 13:56:44 +08:00
#include "NoticeMsg.h"
SINGLETON_STORAGE(NoticeMsg);
NoticeMsg::NoticeMsg()
{
init();
}
NoticeMsg::~NoticeMsg()
{
}
bool NoticeMsg::init()
{
if (!Node::init())
{
return false;
};
return true;
}
void NoticeMsg::ShowTopMsg(std::string strText)
{
Size wndSize = Director::getInstance()->getWinSize();
Sprite* pSprite = Sprite::create("common/Img/TopBack.png");
pSprite->setAnchorPoint(Vec2(0, 0));
pSprite->setPositionY(wndSize.height);
this->addChild(pSprite);
Label* pText = Label::createWithTTF(strText, "common/Font/minijh.TTF", 18);
pText->setAnchorPoint(Vec2(0.5, 0.5));
pText->setPosition(Vec2(pSprite->getContentSize().width / 2, pSprite->getContentSize().height / 2));
pSprite->addChild(pText);
Node* pParent = getParent();
if (pParent == nullptr)
{
Scene* pScene = Director::getInstance()->getRunningScene();
pScene->addChild(this);
}
float fHeight = pSprite->getContentSize().height;
ActionInterval* action1 = MoveTo::create(0.5f, Vec2(0, wndSize.height - fHeight));
ActionInterval* action2 = MoveTo::create(0.5f, Vec2(0, wndSize.height));
//ActionInterval* action1 = FadeIn::create(0.5f);
//ActionInterval* action2 = FadeOut::create(0.5f);
auto call = [=](){
this->removeFromParent();
};
Action* seq1 = Sequence::create(
action1,
DelayTime::create(3.0f),
action2,
CallFunc::create(call),
NULL);
pSprite->stopAllActions();
pSprite->runAction(seq1);
}