小羊驼和你一起学习cocos2d-x之三(进度条、CCProgressTimer)

来源:互联网 发布:淘宝信用等级提升 编辑:程序博客网 时间:2024/04/27 20:29

欢迎转载:请保留原文出处

http://blog.csdn.net/linyongliang?viewmode=list

typedef enum {

/// Radial Counter-Clockwise

kCCProgressTimerTypeRadial,

/// Bar

kCCProgressTimerTypeBar,

} CCProgressTimerType;



CCProgressTimer有别的方法实现 从左到右的进度条

pt->setMidpoint(ccp(0,0));

pt->setBarChangeRate(ccp(1,0));

这两个组合起来就可以了


直接上代码吧: 

pt=CCProgressTimer::create(CCSprite::createWithSpriteFrameName("LoadingBar.png"));//进度条的精灵  pt->setPercentage(0); //开始的百分比位置 最大默认好像是100 pt->setPosition(ccp(pointCenter.x,pointCenter.y*0.5f)); pt->setType(kCCProgressTimerTypeBar);//进度条的类型 大约有两种 请看那个枚举类型。这个是横条的pt->setMidpoint(ccp(0,0));pt->setBarChangeRate(ccp(1,0));this->addChild(pt,100);//你可以通过不断setPercentage来设定进度条的进度 void LayerPlay::updateProgress(float dt){if (progressIndex<100){if (progressIndex<=progressMax){progressIndex+=0.5f;pt->setPercentage(progressIndex);}}else{this->removeChild(pt,true);this->removeChild(spriteLoadingBackgroud,true);this->removeChild(spriteLoading,true);this->unschedule(schedule_selector(LayerPlay::updateProgress));}}//也可以给他跑进度条的动作 CCProgressTo *to = CCProgressTo::actionWithDuration(cd_Time, mPercentage);  // 设定CD时间与要到达的百分比 pt->runAction(to); 

原创粉丝点击