I have recently discovered that the CCProgressTimer class is replaced with CCProgressNode in the latest version of cocos2d, however, when i tried to implement the following code, there is nothing happen to the progressNode I have read all kinds of documentation, it seems like I have used all the latest methods. This all happens in gamePlay Class This is how I define the node.
CCProgressNode *_healthBar;
float _life;
This is the setUp method
- (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];
}
This is how i Involk the change on health bar... (It works, the healthBar is depleting... )
-(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];
}
}