ios cocos2d实现progress(进度条)效果控件源码

6 篇文章 0 订阅
6 篇文章 0 订阅


开发人员: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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值