How do I set a proper health bar?

0 favourites
  • 7 posts
From the Asset Store
Custom animated Health Bar - check youtube video to make it yourself
  • It's been haunting me. I've read this tutorial: scirra.com/tutorials/449/cr ... -healthbar. I followed every step and I still can't figure out how to make a proper health bar for my game. In the tutorial: "Of course, in your games you do not always enter the number of damage or health or maximum health. You will kep'em in variables. And apply this method to the variables is easy." How do I apply this method from the tutorial to my player health instance variable?

    Here's my dilemma: I set my player's instance variable health at start to 100 --> "set barHP sprite width to player.Heath". He defeats a boss, gets a power up, and the power up sets his health to 300 (or some arbritary number). I just want my player's health bar width set steady to just 100px width not 300px. I've been searching everywhere online on how to do it and I still can't figure it out. Can anyone please help me?

    Thank you in advance!

  • Hey, I actually think this recent question of mine could help you with this issue

  • caad8user

    In your specific case, you need two variables. Player_HP and Player_HPMax. Both starts at 100.

    Set HP bar sprite width to ((Player_HP / Player_HPMax) * 100).

    When you upgrade, raise the Player_HPMax to 300. So if the player health is 100/300, the bar width is 1/3 of 100 pixels only. Until you raise the Player_HP.

    You can also apply that to enemies or npcs too if you want to scale their health but keep the bar the same width max.

    Hope that helps you.

  • Thank you so much your help guys! , "Set HP bar sprite width to ((Player_HP / Player_HPMax) * 100)" was the formula that was missing! Thanks a lot! Health bar works properly now.

  • , I'm sorry to bother you. But one more question. Since Player_HP and Player_HPMax are global? How can I "connect" those global variables to my player_Health instance variables? That way, when the player gets hit by an enemy bullet, it subtracts from the player_Health. Is there a way to do this?

    Thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do the bar to any variable, global or instance.

    If instance, you have 2 instance variables for your player sprite.

    1. Health

    2. HealthMax

    Set the bar width to ((Player.Health / Player.HealthMax) * 100)

  • , Thank you so much for your time and help. Your solution worked perfectly.

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