Attach health bar to enemies in family

Get help using Construct 2

Post » Sun Feb 24, 2013 1:37 pm

Hiya

1, I have an enemy family with many different enemies in it.
2, I want each enemy to spawn a health bar at run time.
3, I want the health bar to vanish along with when the enemy is destroyed.

As far I can see, c2 supports bits of but not all of the above at once.. i.e. I can..

1, Use a container to bind one health bar to one enemy type (not a family). Ideally I'd be able to bind objects together in containers at run time but can't see a way to do this.

or

2, Use pegging to peg health bars to enemies at run time but then have another issue:

"Event" EnemyFamily.Health<= 0
   "Subevent"   EnemyFamily.SetAnimation (Dead) < nb. I don't destroy him yet
      "Sub-Subevent"   System HealthBar.Pin.PinnedUID = EnemyFamily.UID (HealthBar.destroy)

This should look for the health bar associated to the enemy who's health just went to 0 but doesn't do anything.silkc22013-02-24 13:39:10
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sun Feb 24, 2013 1:42 pm

[QUOTE=silkc2]

1, Use a container to bind one health bar to one enemy type (not a family). Ideally I'd be able to bind objects together in containers at run time but can't see a way to do this.
[/QUOTE]

You could do it this way:

On familyName created
..Spawn healthbar on familyName (position/imagepont)
..Pin or whateverYouDoWithHealthBars
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Feb 24, 2013 2:09 pm

Yeah that is what I am doing, but that leaves me with cleaning up the health bar object manually which isn't working (see point 2).silkc22013-02-24 14:10:21
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sun Feb 24, 2013 3:17 pm

[QUOTE=silkc2]

      "Sub-Subevent"   System HealthBar.Pin.PinnedUID = EnemyFamily.UID (HealthBar.destroy)
[/QUOTE]

I'd guess this line doesn't actually do any picking, so no health bars are picked here. You could try:

a) saving health bar UID into EnemyFamily variable and using pick by UID condition when destroying the health bar

b) if there is no overlapping in your enemies, pick closest health bar to the dying enemy and destroy that

c) something more elegant :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Feb 24, 2013 3:19 pm

Yeah you are right, still getting my head around why some conditions pick and some do not.

Fixed it using a foreach to get the health bar pinned to enemy (matching on Healthbar.Pin.PinnedID = Enemy.UID).

Would be interested in knowing if there is a way to put containers on families though. silkc22013-02-24 15:20:50
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sat Jan 03, 2015 11:17 am

hi could U post capx sample ? I have the same problem... thanks a lot
B
28
S
10
G
2
Posts: 402
Reputation: 3,915


Return to How do I....?

Who is online

Users browsing this forum: jobel, Timedoor Indones, Yahoo [Bot] and 21 guests