• 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();

    里面的方法说明:

  • 相关阅读:
    apche启动错误|httpd.pid overwritten — Unclean shutdown of previous Apache run?
    查看Mysql版本号 (最简单的是status )
    在不损坏C盘的情况下为C盘扩容,适用于Win
    Python环境配置安装
    用Python建立最简单的web服务器
    MongoDB
    MongoDB
    MongoDB
    MongoDB
    MongoDB
  • 原文地址:https://www.cnblogs.com/aosting/p/3498461.html
Copyright © 2020-2023  润新知