Attach health bar to enemies in family

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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.

  • 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.

    You could do it this way:

    On familyName created

    ..Spawn healthbar on familyName (position/imagepont)

    ..Pin or whateverYouDoWithHealthBars

  • 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).

  •       "Sub-Subevent"   System HealthBar.Pin.PinnedUID = EnemyFamily.UID (HealthBar.destroy)

    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 :)

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • hi could U post capx sample ? I have the same problem... thanks a lot

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)