zoukankan      html  css  js  c++  java
  • 递增和递减进度条CCProgressTimer

    关于scheduleUpdate看这篇即可

    http://www.benmutou.com/blog/archives/56

    接下来是示例代码:

            CCSize size = CCDirector::sharedDirector()->getWinSize();
    
            //创建二个精灵,一绿一红
            CCSprite *psSprite1 = CCSprite::create("green.png");
            CCSprite *psSprite2 = CCSprite::create("red.png");
    
            //利用精灵创建进度条,并设置一些属性
            progresstime1 = CCProgressTimer::create(psSprite1);    //初始化CCProgressTimer
            progresstime1->setPercentage(0.0f);    //设置初始百分比的值
            //progresstime1->setScale(3);            //设置进度条大小为原始的3倍
            progresstime1->setBarChangeRate(ccp(1, 0));    //设置进度条的长度和高度开始变化的大小
            progresstime1->setType(kCCProgressTimerTypeBar);    //设置进度条为水平
            progresstime1->setPosition(ccp(size.width/2, size.height/2));    //放置进度条位置
    
            this->addChild(progresstime1, 100);    //加入Layer中
    
            //利用精灵创建进度条,并设置一些属性
            progresstime2 = CCProgressTimer::create(psSprite2);    //初始化CCProgressTimer
            progresstime2->setPercentage(100.0f);    //设置初始百分比的值
            //progresstime2->setScale(3);            //设置进度条大小为原始的3倍
            progresstime2->setBarChangeRate(ccp(1, 0));    //设置进度条的长度和高度开始变化的大小
            progresstime2->setType(kCCProgressTimerTypeBar);    //设置进度条为水平
            progresstime2->setPosition(ccp(size.width/2, size.height/2 - 30));    //放置进度条位置
    
            this->addChild(progresstime2, 101);    //加入Layer中
            this->scheduleUpdate();
    void HelloWorld::update(float dt)
    {
        //CCProgressTimer *progresstime = static_cast(this->getChildByTag(100));
        float ct1 = progresstime1->getPercentage();    //取得当前进度的百分比
        float ct2 = progresstime2->getPercentage();    //取得当前进度的百分比
    
        ct1 = ct1 + 0.5f;    //每帧+0.5%
        ct2 = ct2 - 0.5f;
    
        //如果进度条小于100%,设置进度条的百分比
        if (ct1 <= 100)    
        {
            CCLOG("progresstime1:%f, progresstime2:%f", ct1, ct2);
            progresstime1->setPercentage(ct1);
            progresstime2->setPercentage(ct2);
        }
        //如果进度条达到100%,则进入过渡场景,过渡场景会在2秒后进入主场景
        else
        {
            CCTransitionFade *tScene = CCTransitionFade::create(2, HelloWorld::scene(), ccWHITE);
            CCDirector::sharedDirector()->replaceScene(tScene);
        }
    }
  • 相关阅读:
    Windows ETW 学习与使用三
    暗云Ⅳ对SATA磁盘MBR Hook探索
    msahci代码调试备份
    mimikatz使用命令记录
    Windows ETW 学习与使用一
    RabbitMQ 实现延迟队列
    Redis 脱坑指南
    浅析 ThreadLocal
    IDEA2020.2.3破解
    用友NC 模块 简写(瞎猜的)
  • 原文地址:https://www.cnblogs.com/newlist/p/3209499.html
Copyright © 2011-2022 走看看