0

在我的应用程序中,每次我的精灵与另一个精灵碰撞时,我希望我的“健康栏”减少 10% 的 100%。我已经把碰撞的东西放下了。我该怎么做?这是我的 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{

 }
4

1 回答 1

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

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

 }
于 2013-06-20T08:17:27.820 回答