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

0 favourites
  • 4 posts
From the Asset Store
Health, Weapon & Rage Bars for your Games. Easy to use & Customize.
  • 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

    (I know how to make a health bar)

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey mekonbekon

    Thanks for the quick response

    it worked

  • FabianB

    Glad to be of help

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