zoukankan      html  css  js  c++  java
  • cocos2dx CCProgressTimer 进度条计时器

    1  创建项目工程

    2 打开win32的项目。

    在HelloWorldScene.h中添加方法。

    1     void update(float dt);
    2     void shwoProssgressBar();

    在HelloWorldScene.cpp中添加方法。

     1 void HelloWorld::update(float dt){
     2     
     3 
     4     CCProgressTimer *timer = (CCProgressTimer *)this->getChildByTag(100);
     5     CCLabelTTF * numsTTF=(CCLabelTTF *)this->getChildByTag(101);
     6     float ct1 = timer->getPercentage();//取得当前进度的百分比
     7      ct1 = ct1 + 0.5f;    //每帧+0.5%
     8 
     9     
    10     //如果进度条小于100%,设置进度条的百分比
    11       
    12     if (ct1 <= 100)
    13         
    14     {
    15         
    16         timer->setPercentage(ct1);
    17                
    18     }
    19     CCString *str= CCString::createWithFormat("%.2f%%",ct1);
    20     numsTTF->setString(str->getCString());
    21 
    22 }
    23 
    24 void HelloWorld::shwoProssgressBar(){
    25     this->setTouchEnabled(true);
    26     CCSize size=CCDirector::sharedDirector()->getWinSize();
    27     
    28     CCSprite *progressSprite=CCSprite::create("progress.png");
    29     CCProgressTimer *timer=CCProgressTimer::create(progressSprite);
    30     timer->setType(kCCProgressTimerTypeBar);  //设置进度条为水平
    31    
    32    // timer->setPercentage(0.0f);    //设置初始百分比的值
    33     timer->setPercentage(0.0f);   
    34     timer->setScale(0.5);          
    35     
    36     //timer->setMidpoint(ccp(0,0));//进度动画运动方向,可以多试几个值,看看效果
    37     //timer->setMidpoint(ccp(1,0));//进度动画运动方向<---
    38     timer->setMidpoint(ccp(0,1));//进度动画运动方向--->
    39 
    40     timer->setBarChangeRate(ccp(1, 0));    //进度条从左到右
    41     //timer->setBarChangeRate(ccp(0, 1));    //进度条高度从低到高.感觉像一个方向向量
    42 
    43     timer->setPosition(ccp(size.width/2-40, size.height-20));    //放置进度条位置
    44     this->addChild(timer,1,100);
    45     
    46     CCLabelTTF * numsTTF=CCLabelTTF::create("0", "Thonburi", 18);
    47     numsTTF->setPosition(ccp(size.width/2-20, size.height-20));
    48     
    49     this->addChild(numsTTF,1,101);
    50 
    51     
    52     this->scheduleUpdate();        //调用定时器更新进度条
    53 }


    bool HelloWorld::init()方法里面添加shwoProssgressBar();

    里面的方法说明:

  • 相关阅读:
    Trie Tree和Radix Tree
    DataNode Layout升级解决Du操作引发的性能问题
    Write-Ahead Log(WAL)的工作原理
    YARN的共享存储服务
    AWS S3存储基于Hadoop之上的一致性保证
    简单聊聊HDFS RBF第二阶段工作近期的一些进展
    基于 Confluence 6 数据中心的 SAML 单点登录设置你的身份提供者
    基于 Confluence 6 数据中心的 SAML 单点登录设置 SSL/TLS
    Confluence 6 基于 Confluence 数据中心的 SAML 单点登录
    Confluence 6 用自带的用户管理
  • 原文地址:https://www.cnblogs.com/aosting/p/3498461.html
Copyright © 2011-2022 走看看