How do I stop a health bar going negative?

Get help using Construct 2

Post » Wed Sep 07, 2016 6:54 am

Hi!

I was following this tutorial to make a mana bar for my game, but I noticed when the hp/mana/whatever reaches a negative value, the bar goes outside the frame in the opposite direction.

I woudnt have notice this in a normal situation, but since I have an ability that will consume mana every second, I noticed once you reach 0 power, the bar keeps going in a negative value.

How could I fix this? Thank you. Appreciate a comment with a hint or tip rather than a capx I dont like copy pastes.

This is the tutorial.

https://www.scirra.com/tutorials/182/ma ... bar?page=4
B
14
S
5
Posts: 252
Reputation: 1,713

Post » Wed Sep 07, 2016 7:54 am

Every second
mana = max(0,mana - 1)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Sep 07, 2016 8:26 am

99Instances2Go wrote:Every second
mana = max(0,mana - 1)


Thanks for replying and helping me out.

But I think that will just fix it for that lonely event, won't really stop the bar from functioning that way. I need a bigger fix.
B
14
S
5
Posts: 252
Reputation: 1,713

Post » Wed Sep 07, 2016 8:47 am

Do you want the mana to go negative ? Or the health, not sure what you display in the bar.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Sep 07, 2016 9:12 am

clamp(x, lower, upper) - Return lower if x is less than lower, upper if x is greater than upper, else return x.
ImageImageImageImage
B
158
S
67
G
43
Posts: 2,603
Reputation: 36,003

Post » Wed Sep 07, 2016 9:54 am

Here, take a look at this capx. Maybe it'll help you out.

https://www.dropbox.com/s/uspynnldbvr0s ... .capx?dl=0
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Wed Sep 07, 2016 10:01 am

99Instances2Go wrote:Do you want the mana to go negative ? Or the health, not sure what you display in the bar.


I want the bar not to grow in the opposite direction. The bar decreases it's size depending on the HP variable. If it reaches 0 it doesn't stop. If you have some event that keeps substracting HP the bar will start going in the opposite direction since it is negative value.

I don't know if I made myself clear, english ain't my mother tongue.
B
14
S
5
Posts: 252
Reputation: 1,713

Post » Wed Sep 07, 2016 10:02 am

heyguy wrote:Here, take a look at this capx. Maybe it'll help you out.

https://www.dropbox.com/s/uspynnldbvr0s ... .capx?dl=0


Worked for me. Thanks!
B
14
S
5
Posts: 252
Reputation: 1,713

Post » Wed Sep 07, 2016 10:20 am

No problem, glad it helped!
B
30
S
15
G
22
Posts: 183
Reputation: 14,221


Return to How do I....?

Who is online

Users browsing this forum: warmty and 4 guests