http://shahdza.blog.51cto.com/2410787/1546707/
void ManagerScene::loading(void) {
// 点击屏幕继续
CCLabelTTF *touchContinue = CCLabelTTF::create("载入中......","Arial",28);
touchContinue->setAnchorPoint(ccp(0.5f, 0.5f));
touchContinue->setPosition(ccp(250,480));
//touchContinue->setVisible(false);
addChild(touchContinue);
m_touchLoading = touchContinue;
CCLabelTTF *touchget = CCLabelTTF::create("点击屏幕领取礼包","Arial",28);
touchget->setAnchorPoint(ccp(0.5f, 0.5f));
touchget->setPosition(ccp(250,480));
touchget->setVisible(false);
this->addChild(touchget);
m_touchGet = touchget;
// 文字闪动
CCAction *act = CCRepeatForever::create(
CCSequence::createWithTwoActions(CCFadeOut::create(0.7f),
CCFadeIn::create(0.2f)));
touchget->runAction(act);
// 进度条
CCSprite *loadingBg = CCSprite::create("loading/bg_1.png");
loadingBg->setPosition(ccp(200,480));
addChild(loadingBg);
m_loadingBg = loadingBg;
CCSprite *loadingPrg = CCSprite::create("loading/bg_2.png");
CCProgressTimer *loadingBar = CCProgressTimer::create(loadingPrg);
loadingBar->setType(kCCProgressTimerTypeBar);
// Setup for a bar starting from the left since the midpoint is 0 for the x
loadingBar->setMidpoint(ccp(0.5,1));
// Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
loadingBar->setBarChangeRate(ccp(0, 1));//ccp(1, 0)
loadingBar->setPercentage(0);
loadingBar->setPosition(ccp(200,480));
addChild(loadingBar);
m_loadingBar = loadingBar;
}
void ManagerScene::onProgress(void)
{
// 分五次加载: 0-20,
float prg = m_loadingBar->getPercentage();
if (prg >= 100.0f)
{
m_loadingBg->setVisible(false);
m_touchLoading->setVisible(false);
m_touchGet->setVisible(true);
} else
{
float delta =10;
float to;
if ((prg + delta) >= 100.0f)
{
delta = 100 - prg;
to = 100.0f;
m_loadingBar->setPercentage(100);
onLoadingFinish();
} else
{
to = prg + delta;
}
float time = delta * s_timePerProgress; // 1个进度需要的时间
CCProgressFromTo *prgAct = CCProgressFromTo::create(time, prg, to);
m_loadingBar->runAction(
CCSequence::create(
prgAct,
CCCallFunc::create(this, callfunc_selector(ManagerScene::onProgress)),
NULL
)
);
}
}