Healthbar Width Problem

I have a healthbar that works but the problem is when the image of the healthbar shrinks, it moves to the left on overlaps the healthbar back.
From this:
image
To this:
image
It overlaps the healthbar back.
The formula I use is:


imagewidth / maxhealthvariable * currenthealthvariable
It works fine but the image slowly moves left when it shrinks.
Hope someone will help me out. Thanks in advance!

1 Like

Oh i think i got this

try add this condition

Player health is larger or = to 0

so it doesn’t go to negative numbers

1 Like

This is also fine and you can use clamp expression too:
clamp(variable(health), min value, max value)

2 Likes

cool i learned something new :slight_smile:

1 Like

Hi, your event is fine actually.
It’s the image itself it has empty space:
image

In your image editor the bar may look like this, notice the white checkered space:


The white checkered space is transparent area, and might be causing your issue.

Crop your health bar so it’s only like this, and save it:
image

Then, your healthbar will be a bit off in GDevelop. Move it to the correct position, and your healthbar image should shrink very fine!

2 Likes

Yup! I forgot to crop it that’s why it has an invisible part an excess that ruins the healthbar. I fixed it now. Thank you @reina @Aesomorph and @Muzan!

1 Like