0
votes

In my app, I want my "health bar" to decrease by 10 percent out of 100 percent each time my sprite collides with another sprite. I already have the collision stuff down. How would I do this? Here is the code in my init to create the progress timer:

    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);

And this is where I want to incrementally decrease the progress timer from 100 percent by 10 percent:

-(void)subtractLife{

 }
1
schedule a function with a small time delay and then decrease the percentage in that functionHamdullah shah

1 Answers

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

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

 }