开发人员:Jason's.Alex QQ:531401335
csdn博客:http://blog.csdn.net/RuShrooM
//
// CCProgressTimerEffect.h
// DiceGameBox2D
//
// Created by jasonsalex on 13-1-27.
//
//自定义进度条
#import "cocos2d.h"
#import "ConstDefine.h"
@interface CCProgressTimerEffect : CCProgressTimer
{
float maxValue;//最大值
float curValue;//当前数值
CCSprite *bgSprite;//背景图片
CCLabelTTF *valueTTF;//数值显示文本
}
@property(readwrite) float maxValue;
+(id)progressTimerWithEffect:(float)max_value background:(id)bg frontground:(id)fg;
-(id)initWithProgressTimerEffect:(float)max_value background:(id)bg frontground:(id)fg;
@end
//
// CCProgressTimerEffect.m
// DiceGameBox2D
//
// Created by jasonsalex on 13-1-27.
//
//
#import "CCProgressTimerEffect.h"
#import "ResourceLoad.h"
@implementation CCProgressTimerEffect
@synthesize maxValue;
+(id)progressTimerWithEffect:(float)max_value background:(id)bg frontground:(id)fg
{
return [[[self alloc]initWithProgressTimerEffect:max_value background:bg frontground:fg]autorelease];
}
-(id)initWithProgressTimerEffect:(float)max_value background:(id)bg frontground:(id)fg
{
if(self=[super initWithFile:fg]);
{
maxValue=max_value;
bgSprite=[CCSprite spriteWithFile:bg rect:[self boundingBox]];
id strValue=[NSString stringWithFormat:@"0/%i",(int)maxValue];
valueTTF=[CCLabelTTF labelWithString:strValue fontName:DefaultFontName fontSize:DefaultFontSize];
CGSize size=[self boundingBox].size;
size.width*=0.5f;
size.height*=0.5f;
[valueTTF setPosition:ccp(size.width,size.height)];
[bgSprite setPosition:[valueTTF position]];
[self addChild:valueTTF];
[self addChild:bgSprite z:-1];
}
return self;
}
-(void)dealloc
{
NSLog(@"~ProgressTimer");
[super dealloc];
}
-(void)setPercentage:(float)percentage
{
curValue=percentage;
id str=[NSString stringWithFormat:@"%i/%i",(int)curValue,(int)maxValue];
[valueTTF setString:str];
[super setPercentage:curValue/maxValue*100.0f];
}
@end