Cocos2d-CCProgressTimer[条状进度条,圆形进度条]
CCSprite* watch=[CCSprite spriteWithFile:@"office_watch.png"];
[self addChild:watch]; //表的背景;
watch.position=ccp(250, 160);
spoint=[CCSprite spriteWithFile:@"office_point.png"];
spoint.position=ccp(250,160); //表的背景2
[self addChild:spoint];
// 进度条
timer= [CCProgressTimer progressWithFile:@"office_watchback.png"];
timer.type = kCCProgressTimerTypeRadialCW; //类型设为圆形进度条,顺时针旋转;
timer.position = ccp(250,160);
timer.percentage = 0.0f;
[self addChild:timer];
indicator=[CCSprite spriteWithFile:@"office_indicator.png"];
indicator.anchorPoint=ccp(86.0f/171.0f,83.0f/162.0f); //表针锚点一定要定在表针旋转点上;
indicator.position=ccp(250,160); //表针
[self addChild:indicator];
[self schedule:@selector(timeGo) interval:1];
一秒钟调用一次timeGo:
-(void)timeGo
{
CCLOG(@"%f",numScore);
numScore=numScore+5.0/3.0;
CCRotateBy* rotateBy=[CCRotateBy actionWithDuration:0 angle:6]; //一秒钟表针旋转6度;
[indicator runAction:rotateBy];
if (numScore<=100) {
timer.percentage=numScore; //进度条增加;
}
}
效果图:

条状进度条:
CCSprite* backGround=[CCSprite spriteWithFile:@"office_progress.png"];
backGround.position=ccp(150,50); //进度条背景;
[self addChild:backGround z:0];
CCProgressTimer* pro=[CCProgressTimer progressWithFile:@"office_normal.png"];
pro.position=ccp(150, 50); //进度条,位置跟进度条背景位置相同;
pro.type=kCCProgressTimerTypeHorizontalBarLR;
[self addChild:pro z:0 tag:10];
[self schedule:@selector(go) interval:1];
函数go:
-(void)go
{
CCProgressTimer* timer=(CCProgressTimer*)[self getChildByTag:10]; //通过tag获取sprite必须进行一下类型转化;
timer.percentage+=5.0f; //一秒钟进度条走%5;
}
效果图:

进度条显示类型:
- kCCProgressTimerTypeRadialCCW, 扇形逆时针形式
- kCCProgressTimerTypeRadialCW, 扇形顺时针形式
- kCCProgressTimerTypeHorizontalBarLR, 从左往右增张的形式
- kCCProgressTimerTypeHorizontalBarRL, 从右往左增张的形式
- kCCProgressTimerTypeVerticalBarBT, 从下往上增张的形式
- kCCProgressTimerTypeVerticalBarTB, 从上往下增张的形式

浙公网安备 33010602011771号