How do I use one health bar for one type of enemie

Get help using Construct 2

Post » Tue Apr 18, 2017 5:17 pm

Hey guys :)

Just one health bar for one type of enemie, and you can see the bar on every enemie of that kind at the same time.

How can i do it?

Thanks ;)

Sorry for my bad english :P

(I know how to make a health bar)
B
7
S
1
Posts: 72
Reputation: 610

Post » Tue Apr 18, 2017 5:34 pm

Do you mean each enemy has it's own health bar, for example over its own head?

If so, create a sprite called "healthbar" Add the pin behaviour to it. Add an instance variable called initialWidth and set it to the starting width you want for the healthbar.
Add it to a container with the enemy; when an enemy is created it will automatically create a healthbar object. Give the enemy "health" and "healthMax" instance variables - set both of these to the max health of the enemy.

Add this code:

On enemy created: Set healthbar position to (enemyX, enemyY-(enough pixels so that it appears above the enemy's head))
Pin healthbar to enemy.


When an enemy takes damage you want to reduce the width of the health bar, e.g.:

If enemy collides with bullet: enemy|subtract 1 from health
healthbar set width to healthbar.initialWidth*(enemy.health)/(enemy.healthMax)

Because the healthbar is in a container with the enemy, only the healthbar for that enemy will be affected.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue Apr 18, 2017 6:37 pm

Hey mekonbekon

Thanks for the quick response

it worked :)
B
7
S
1
Posts: 72
Reputation: 610

Post » Tue Apr 18, 2017 7:16 pm

@FabianB

Glad to be of help :)
B
20
S
8
G
3
Posts: 458
Reputation: 4,055


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 33 guests