How do I make enemies with health bars?

Get help using Construct 2

Post » Sat May 09, 2015 1:15 pm

Hello guys I know there are already many tutorials/discussions on how to create a health bar for all enemies on the layout but when I read them I still don't understand... If you have time could you explain step by step & with images if possible?

The help i need with is:
Currently I have enemy on the layout from the start of the game but how to make for each enemy it's own healthbar so if I shoot 1 of the enemy it will only subtract health from 1 enemy not all of them. and if one dies play death animation only on the enemy that has < less then 1 Health.


Thank you very much for any help! Much appreciated!
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 1:20 pm

give the healthbar an instance variable with the value of the enemys UID. That's one way how to connect them.
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat May 09, 2015 1:32 pm

@Fireche how do I set an UID to the enemies?
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 1:38 pm

@Frap1K Every object has a UID (Unique ID) after spawning. You don't need to set it.
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat May 09, 2015 1:52 pm

@Fireche

Is this correct?
Image

And how/where do I put value of the enemies UID?
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 2:20 pm

@Frap1K create a new instance variable for the hpbar. When a new enemy spawns you spawn aswell a new hpbar and set its instance variable to the UID of the enemy UID.
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat May 09, 2015 2:34 pm

@Fireche But that works with every tick >> spawn object? Is it the same as if I just place them on the map/overlay? like it's shown above on the image?
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 2:41 pm

yes..you can simply place it that will work aswell. Or you can make a code which will look like this: "pick every enemy -> enemy spawn hpbar -> hpbar set instance variable to enemy.UID"
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat May 09, 2015 3:19 pm

Rather than doing it using UID, use containers from the properties bar on the left and add a single healthbar object into the container of the enemy/unit. Then you can just do something like this capx: https://dl.dropboxusercontent.com/u/471 ... thBar.capx (pretty much the same as the Construct Classic one actually :-P )

To learn more about containers check this manual page: https://www.scirra.com/manual/150/containers

If you only wanted enemy healthbars to appear when the enemy is being hurt, make it visible/invisible rather than creating and destroying it (as objects in containers are created and destroyed together automatically).

Hope that helps! :)
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit Dropbox is a pile of trash and if you need my old files PM me! :)
B
124
S
42
G
17
Posts: 2,225
Reputation: 19,887

Post » Sat May 09, 2015 3:50 pm

@Jayjay Trying this now thank you for replying!
B
8
S
3
Posts: 120
Reputation: 989

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests