Health Bar
GingerBGames
Member Posts: 390
Hello fellow gs'ers,
I was just wondering if someone could lend a hand with this one? I have a health bar that goes down as my main character is hit, my problem is when I say destroy actor and rest level, I get the black screen of bad code. Can anyone tell how they've done this.
In my health bar actor I have the following:
Constrain attribute: self.Size.Width TO game.Life*20
Constrain attribute: self.position.x TO 20+(self.Size.Width/2)
Is this where I would add the when 0 destroy actor? I have no idea where to put that code, in with the health bar or the actor? Thank you to anyone that can help.
I was just wondering if someone could lend a hand with this one? I have a health bar that goes down as my main character is hit, my problem is when I say destroy actor and rest level, I get the black screen of bad code. Can anyone tell how they've done this.
In my health bar actor I have the following:
Constrain attribute: self.Size.Width TO game.Life*20
Constrain attribute: self.position.x TO 20+(self.Size.Width/2)
Is this where I would add the when 0 destroy actor? I have no idea where to put that code, in with the health bar or the actor? Thank you to anyone that can help.
Comments
You have to add to your life bar:
If life = 0
change attribute life to 20
And of course change attribute available life to available life -1
if you show available lives and want to count them down.
I mean, whit this you recharge your life bar only and count down available lives.
You count your life bar on the game actor itself.
If it is a soldier i.e. and it gets shot with a gun, every gun hit counts 1 down from the life bar. If the life bar is 0, you have to destroy your game actor with
if life = 0
destroy
If you want to spawn a new soldier for the next round, you add to the life bar (or any other actor which spawns your soldier):
if life = 20
spawn actor soldier
If the whole game has one life bar, then make a game attribute, if every actor on the screen has an own life bar, then make life a self attribute.