0
我正在使用CCProgressTimer爲HP欄編寫遊戲。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 increase HP:1],HP欄會消失。
任何人都可以幫忙嗎?