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];
}
以上是计算损害所用的方法。 每当参与者打什么东西时都会被叫到。 它是由一个称为“身体残疾”的班子创建的。
这部法律是用来为损害之 bar取面罩。 这只是一次行动,我怎么能够以与损失相同的数量来处理这个问题?
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)];