Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone CCProgressTimer不';我不能正常工作_Cocos2d Iphone - Fatal编程技术网

Cocos2d iphone CCProgressTimer不';我不能正常工作

Cocos2d iphone CCProgressTimer不';我不能正常工作,cocos2d-iphone,Cocos2d Iphone,我正在为HP bar编写一个使用CCProgressTimer的游戏 以下是我添加HP工具栏的代码: _hpBar = [CCProgressTimer progressWithSprite:[CCSprite spriteWithFile:@"hp_bar.png"]]; _hpBar.type = kCCProgressTimerTypeBar; _hpBar.barChangeRate = ccp(1, 0); // Y stays the same _hpBar.midpo

我正在为HP bar编写一个使用CCProgressTimer的游戏

以下是我添加HP工具栏的代码:

_hpBar = [CCProgressTimer progressWithSprite:[CCSprite spriteWithFile:@"hp_bar.png"]];
_hpBar.type = kCCProgressTimerTypeBar;
_hpBar.barChangeRate = ccp(1, 0);       //  Y stays the same
_hpBar.midpoint = ccp(0, 0);
_hpBar.percentage = 100;
_hpBar.position = ccp(_hpBar.contentSize.width * scale / 2, self.contentSize.height + _hpBar.contentSize.height / 2 + 2);
[self addChild:_hpBar];
添加以下是我的代码以提高HP:

- (int)increaseHP:(int)amount {
    _life = MIN(_life + amount, 100);
    if (_life > 30) [_hpBar setSprite:[CCSprite spriteWithFile:@"hp_bar.png"]];
    [_hpBar setPercentage:_life];
    return _life;
}
但是,当HP满了,即_life=100,然后我再增加一些HP,即调用[self-increaseHP:1],HP栏将消失


有人能帮忙吗?

因为百分比从0到100,并且>100%的行为未定义(不受保护)

如果你的角色可以拥有,比如说最大250 HP,那么你需要计算角色拥有的生命值百分比。例如,如果他有125马力的话,那将占50%