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

Get help using Construct 2

Post » Sun Feb 26, 2017 9:03 pm

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...
B
11
S
6
Posts: 19
Reputation: 1,086

Post » Sun Feb 26, 2017 9:42 pm

% 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
B
8
S
3
G
1
Posts: 15
Reputation: 705

Post » Sun Feb 26, 2017 11:51 pm

bambo wrote:% 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.
B
11
S
6
Posts: 19
Reputation: 1,086

Post » Mon Feb 27, 2017 12:48 am

venoxis wrote:
bambo wrote:% 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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780

Post » Mon Feb 27, 2017 3:43 pm

lamar wrote:
venoxis wrote:
bambo wrote:% 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 =/
B
11
S
6
Posts: 19
Reputation: 1,086

Post » Mon Feb 27, 2017 4:18 pm

Check that your flash and pause is long enough to be seen otherwise it will look like it is always on.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780

Post » Fri Mar 17, 2017 11:12 am

Hey, just out of curiosity, how do you change the color of your sprite though? Are you using fx?
B
9
S
3
Posts: 26
Reputation: 794

Post » Fri Mar 17, 2017 11:20 am

@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.
B
9
S
2
Posts: 69
Reputation: 833


Return to How do I....?

Who is online

Users browsing this forum: Bootfit and 9 guests