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);
        }
    }
  • 相关阅读:
    elform 校验
    深入理解ES6系列
    【数据结构&算法】10串基础&KMP算法源码
    【数据结构&算法】13赫夫曼树&赫夫曼编码
    【RTOS】FreeRTOS中的任务堆栈溢出检测机制
    【数据结构&算法】11树基础&二叉树遍历
    【环境】解决linux与windows之间的复制粘贴
    【数据结构&算法】09队列概念&参考源码
    【网络基础】内网IP与外网IP
    【数据结构&算法】12线索二叉树
  • 原文地址:https://www.cnblogs.com/newlist/p/3209499.html
Copyright © 2011-2022 走看看