如何在cocos2d中逐步减少10%的CCProgressTimer?

时间:2013-06-20 01:51:17

标签: ios6 cocos2d-iphone xcode4.5

在我的应用程序中,每当我的精灵与另一个精灵碰撞时,我希望我的“健康栏”减少百分之十,百分之十。我已经把碰撞了。我该怎么做?这是我的init中创建进度计时器的代码:

    CCSprite *healthFull = [CCSprite spriteWithFile:@"Health Bar.png"];
    CCSprite *healthBorder = [CCSprite spriteWithFile:@"Health Bar Border.png"];
    [self addChild:healthBorder z:5];
    healthBorder.position = ccp(size.width / 2, 300);
    health = [CCProgressTimer progressWithSprite:healthFull];
    health.type = kCCProgressTimerTypeBar;
    health.midpoint = ccp(1,0); // starts from right
    health.barChangeRate = ccp(-1,0); // grow only in the "x"-horizontal direction
    health.percentage = 100; // (0 - 100)
    [self addChild:health];
    health.position = ccp(size.width /2, 300);

这就是我想逐步将进度计时器从100%减少10%的原因:

-(void)subtractLife{

 }

1 个答案:

答案 0 :(得分:0)

-(void)subtractLife{
     health.percentage-=10;

    if(health.percentage<0)
        health.percentage = 0;

 }
相关问题