CCProgressFromTo 加载

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
                )
        );
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值