Files
wnmj/Classes/Scenes/LoadingScene.cpp
2026-02-13 14:34:15 +08:00

95 lines
1.8 KiB
C++

#include "LoadingScene.h"
SINGLETON_STORAGE(LoadingScene);
LoadingScene::LoadingScene()
{
init();
}
LoadingScene::~LoadingScene()
{
}
bool LoadingScene::init()
{
if (!Node::init())
{
return false;
};
auto visibleSize = Director::getInstance()->getVisibleSize();
//触摸屏蔽层
auto touchLayer = LayerColor::create(Color4B(0, 0, 0, 50), visibleSize.width, visibleSize.height);
this->addChild(touchLayer);
auto mListener = EventListenerTouchOneByOne::create();
mListener->onTouchBegan = [=](Touch * _touch, Event * _event)
{
return true;
};
mListener->setSwallowTouches(true);
//不用手动删除(addEventListenerWithFixedPriority需要手动删除)
_eventDispatcher->addEventListenerWithSceneGraphPriority(mListener, this);
//加入loading图片
m_sprLoading = Sprite::create("common/Img/ico_loding.png");
m_sprLoading->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
touchLayer->addChild(m_sprLoading);
return true;
}
void LoadingScene::onEnter()
{
Node::onEnter();
}
void LoadingScene::onEnterTransitionDidFinish()
{
Node::onEnterTransitionDidFinish();
}
void LoadingScene::onExit()
{
Node::onExit();
}
//显示
void LoadingScene::show(Node* Parent /*= nullptr*/)
{
this->removeFromParent();
// 未提供父
if (nullptr == Parent)
{
//如果没有被加入场景则加入当前运行场景
if (getParent() == nullptr)
{
Scene* pScene = Director::getInstance()->getRunningScene();
pScene->addChild(this, 99999);
}
}
else
{
Parent->addChild(this, 99999);
}
auto callback = [this](){
hide();
};
auto rotate = Sequence::create(Repeat::create(RotateBy::create(1.6f, 360), 8), CallFunc::create(callback), nullptr);
m_sprLoading->runAction(rotate);
}
//隐藏
void LoadingScene::hide()
{
m_sprLoading->stopAllActions();
this->removeFromParent();
}