How do I health bars

Get help using Construct 2

Post » Thu Apr 02, 2015 10:02 pm

i've managed to create healthbar and pin it to each enemy (when you hit them first time)
but now i can't get to manage those healthbar to reduce their size when hit 2nd 3rd and so on time.
how do you manage that? also would like to destroy it when enemy dies. (can't use container because there's a death animation that loops later
and enemy isn't destroyed until it leaves layout)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Thu Apr 02, 2015 10:19 pm

Sounds like you're pinning a healthbar to an enemy and hoping that hitting the enemy, the healthbar will automatically reduce... am I right?

Every enemy instance, create an instance variable called healthbarUID or something.
When pinning the healthbar, store the healthbar's UID in he enemy instance variable healthbarUID.
Then whenever an enemy is hit, also pick the healthbar from healthbarUID and reduce it.
Same method for destroying. When you're destroying the enemy, pick the healthbar with that UID and destroy it first, then destroy the enemy.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Post » Thu Apr 02, 2015 11:54 pm

If the health bar is a progress bar, and only one instance, then:
[code]When Enemy is Hit:
set progress ProgressBar.Progress-1
B
5
Posts: 16
Reputation: 259

Post » Fri Apr 03, 2015 12:26 am

you need to make instance variables that contain the UID and pick the healthbar based on which enemy is hit.

Create Enemy
Enemy Spawn Healthbar
Healthbar.EnemyUID = Enemy.UID (make an instance variable in Healthbar called EnemyUID)

PlayerFire on collision with Enemy (when the player shoots the enemy
pick Healthbar where Healthbar.EnemyUID == Enemy.UID
set Healthbar width to self.width - PlayerFire.damage (or whatever)

then add

if Enemy.health < 0 then destroy
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Fri Apr 03, 2015 2:35 pm

thought so, but i was hoping there was a simpler workaround for picking instances :/
kinda clutters event sheet.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450


Return to How do I....?

Who is online

Users browsing this forum: beguinner, mcscooter, totoe, Yahoo [Bot] and 21 guests