Cocos2d-x提供了进度条动作,该类继承CCActionInterval。继承关系如下:
在使用CCProgressto时还需要CCProgresstimer。
在CCProgresstimer类中,仅仅只有一个create函数用来创建,其参数是一个精灵,如下:
static CCProgresstimer* create(CCSprite* sp);
CCProgresstimer在创建后,还需要设置一些其他参数。
CCProgressto类中也仅仅有一个create用来创建,代码如下:
/** Creates and initializes with a duration and a percent */ static CCProgressto* create(float duration,float fPercent);float duration:进度条执行完需要的时间。
float fPercent:进度条的百分比,100是进度条满。
一、辐射性进度条
实例:
CCProgressto* radial = CCProgressto::create(2,100); CCProgresstimer* radialProgress = CCProgresstimer::create(CCSprite::create("btn_go_0.png")); radialProgress->setType(kCCProgresstimerTypeRadial); radialProgress->setposition(ccp(100,100)); radialProgress->setMIDpoint(ccp(0.1,0.2)); radialProgress->setReverseProgress(true); radialProgress->runAction(radial); addChild(radialProgress);
setType:用来设置进度条的类型。
setMIDpoint:用来设置旋转中心。
setReverseProgress:用来设置进度条执行方向,默认是顺时针。
MIDpoint与barChangeRate声明如下:
/** * MIDpoint is used to modify the progress start position. * If you're using radials type then the mIDpoint changes the center point * If you're using bar type the the mIDpoint changes the bar growth * it expands from the center but clamps to the Sprites edge so: * you want a left to right then set the mIDpoint all the way to ccp(0,y) * you want a right to left then set the mIDpoint all the way to ccp(1,y) * you want a bottom to top then set the mIDpoint all the way to ccp(x,0) * you want a top to bottom then set the mIDpoint all the way to ccp(x,1) */ CC_PROPERTY(CCPoint,m_tMIDpoint,MIDpoint); /** * This allows the bar type to move the component at a specific rate * Set the component to 0 to make sure it stays at 100%. * For example you want a left to right bar but not have the height stay 100% * Set the rate to be ccp(0,1); and set the mIDpoint to = ccp(0,.5f); */ CC_SYNTHESIZE(CCPoint,m_tbarChangeRate,barChangeRate);二、条状进度条
实例:
CCProgresstimer * barProgress = CCProgresstimer::create(CCSprite::create("btn_go_0.png")); CCProgressto * bar = CCProgressto::create(2,100); barProgress->setType(kCCProgresstimerTypebar); barProgress->setMIDpoint(ccp(1,0)); barProgress->setbarChangeRate(ccp(1,1)); barProgress->setposition(ccp(200,100)); barProgress->runAction(bar); addChild(barProgress);具体辐射性进度条已经解释。 总结
以上是内存溢出为你收集整理的我的Cocos2d-x学习笔记(十七)CCProgressTo全部内容,希望文章能够帮你解决我的Cocos2d-x学习笔记(十七)CCProgressTo所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)