Cocos2d iphone CCProgressTimer不';我不能正常工作
我正在为HP bar编写一个使用CCProgressTimer的游戏 以下是我添加HP工具栏的代码: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
_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%