how do l make a actor destroy it's self when it's life bar runs out?
nblsoccer
Member Posts: 8
Anyone, if you wouldn't mind helping me, I would appreciate it if you could. I need to know how to destroy my actor when it's life bar run's out. I've just started so, please don't make it to complicated.
Thank you.
Answers
Create an attribute (integer) in the scene called life bar and put a number into it that is equal to the amount of life.
When your character gets hit, make a rule inside your actor.
if actor overlaps or collides with actor (e.g. bullet)
change attribute game>life bar to game>lifebar-1
create another rule inside actor:
if attribute game>life bar = 0
destroy actor
hope this helps!
I have a couple tutorials about creating and displaying health bars if you want to check them out:
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
I'm sorry, I'm an idiot. I don't understand anything anybody said. Thank though.
Let's take @jsorr2's advice, which is good and break it down a bit to see if that helps:
Are you able to create an integer attribute called game.lifeBar with a starting value of... say 3?
This is just so that there is a reason for the life decreasing. Are you able to create a new rule with the condition set to actor "overlaps or collides with" and then select another actor such as a bullet for it to collide with?
Inside of that new rule, add a Change Attribute behavior and select game.lifeBar on the left side of the behavior and then -- using the 'e' expression editor button -- select game.lifeBar and type "-1" after it to subtract one from that attribute. Are you able to do that?
Are you able to create another new rule with the condition set to attribute game.lifeBar=0? And can you add a Destroy Actor behavior to that rule and set the actor name to the actor itself?
If you let us know where you're having problems, we can help you get past that spot.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
thank you so much tatiang. I needed so much help doing this.
thank you.
You're very welcome!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
that helped me so much.