How do I make my health bar change based on health%

0 favourites
  • 8 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • i want my health bar sprite to change color based on a ''player'' sprite variable called health to change animation when player health is ≥ to 50% of player max health

    i can't figure out how to as everytime i try to use % in the value it say its missing something etc...

  • % is a symbol of modulo (reminder after division) e.g. 10%3 gives 1.

    If you want to check if player's health is more than 50% you should compare this: player.health/player.maxHealth>=0.5

  • % is a symbol of modulo (reminder after division) e.g. 10%3 gives 1.

    If you want to check if player's health is more than 50% you should compare this: player.health/player.maxHealth>=0.5

    i want to check it in % because i might have the player max health be upgradable so 100% health could go from 100 to 150 +, etc...

    that's why.

  • > % is a symbol of modulo (reminder after division) e.g. 10%3 gives 1.

    >

    > If you want to check if player's health is more than 50% you should compare this: player.health/player.maxHealth>=0.5

    >

    i want to check it in % because i might have the player max health be upgradable so 100% health could go from 100 to 150 +, etc...

    that's why.

    Use a global variabe for Max Health and one for Set Health that way you can change it as the game progresses.

    MaxHealth=100

    SetHealth=100

    On Player Collision with Enemy: Subtract 10 from MaxHealth

    On MaxHealth < SetHealth/2: Change HealthBar Sprite

    That way you can change SetHealth later in the game to a higher number and the event adjusts. When you change SetHealth make sure you also set MaxHealth to that same number to start.

  • >

    > > % is a symbol of modulo (reminder after division) e.g. 10%3 gives 1.

    > >

    > > If you want to check if player's health is more than 50% you should compare this: player.health/player.maxHealth>=0.5

    > >

    >

    > i want to check it in % because i might have the player max health be upgradable so 100% health could go from 100 to 150 +, etc...

    >

    > that's why.

    >

    Use a global variabe for Max Health and one for Set Health that way you can change it as the game progresses.

    MaxHealth=100

    SetHealth=100

    On Player Collision with Enemy: Subtract 10 from MaxHealth

    On MaxHealth < SetHealth/2: Change HealthBar Sprite

    That way you can change SetHealth later in the game to a higher number and the event adjusts. When you change SetHealth make sure you also set MaxHealth to that same number to start.

    i kinda got it to work on my own, but there is a problem, ive put the flash behavior on my tiled background but it doesn't flash when it should be =/

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Check that your flash and pause is long enough to be seen otherwise it will look like it is always on.

  • Hey, just out of curiosity, how do you change the color of your sprite though? Are you using fx?

  • Milupa5

    To easily change the colour of a sprite on the fly then use the effect "SetColor" or "Adjust HSL".

    If your sprite is black and white/Greyscale, SetColor lets you apply a blanket colour to it.

    If your sprite already has some colour in it, use "Adjust HSL" to modify the existing colour.

    You can modify the parameters for these effects through the event systems.

    These effects are expensive on mobile but should be fine if you don't overuse them.

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