Hi everyone
I have a question in game development. I am building a game for iPhone. At the game play, there is a damage bar, that displays what the player has damage the enemies. The technique I use is using 2 pictures. One is a damage bar which is fill with full damage, and one is jus a black bar but same size with the damage bar. It is like masking. I will scale the black bar shorter whenever it receives the value of the damage. But the problem here is the method i use to calculate the damage is different class from the method i use to draw the black bar. How do I draw it frequently everytime it gets a damage value? please help me , thank you so much.
-(void)damageTaken
{
totalDamage = 0;
for (uint i = 0 ; i< [bodyParts count]; i++) {
RagdollBodypart *part = (RagdollBodypart *)[bodyParts objectAtIndex:i];
totalDamage += part.damage;
}
[[NSNotificationCenter defaultCenter] postNotificationName:DAMAGE_TAKEN object:nil];
}
above is the method I used to calculate the damage. It will get called everytime the player hits something. It is created in a class called BodyDamage
This is the code i use to draw the mask for the damage bar. it just runs once, how can I run this with the number of time same as the damageTaken?
float damage = [[GameController instance].engine.enemies totalDamage];
float scale = (float)(1400 -damage)/(float)1400;
[damageSprMask setScaleY:scale];
//[damageSprMask setPosition:ccp(20,150)];
[damageSprMask setPosition:ccp(20,150 +((1- damageSprMask.scaleY)*damageSpr.contentSize.height)/2)];