最近发现在最新版本的cocos2d中CCProgressTimer类被替换为CCProgressNode了,但是,当我尝试实现下面的代码时,progressNode没有任何反应我看了各种文档,好像我有使用了所有最新的方法。这一切都发生在 gamePlay 类这就是我定义节点的方式。
CCProgressNode *_healthBar;
float _life;
这是设置方法
- (void)initializeHealthBar {
self->_healthBar = [[CCProgressNode alloc] init]; // This wasn't there before, but thought it might be the memory allocation problem,
// _health is the code connection between sprite builder and Xcode.
self->_healthBar = [CCProgressNode progressWithSprite:_health];
[_healthBar setType:CCProgressNodeTypeBar];
[_healthBar setPercentage:_life];
[_healthBar setBarChangeRate:ccp(0.1,0.1)];
_healthBar.position = _health.position;
// So the _healthBar turns out positioned correctly, because _health is already positioned in sprite builder
[_contentNode addChild:_healthBar];
}
这就是我对健康栏进行更改的方式......(它有效,健康栏正在耗尽......)
-(void) hit {
if(_healthBar.percentage > 0)
{
self->_life -= 34;
self->_healthBar.percentage -= 34;
}
if (self->_healthBar.percentage <= 0 && ![_myHero isGameOver]) {
self->_healthBar.percentage = 0;
[_myHero isGameOver: TRUE];
[self gameOver];
}
}