Hp suggest solution

I would like to solve a problem of graphic aspect … in practice the pixels of the energy bar are 394 x 40 while the hp can be 100 at most now … among the various solutions seen and suggested I do not find anything similar …
how do i take 10 hp damage and cut a piece of energy bar graphics in proportion to the damage received ???
has anyone ever had similar issues … I could change the bar but it would bother me because this one I have is really nice … and if I try to change the size I ruin the graphics …

You could do something like set a Variable Damage to (energybar.Width()/10) and then change X width of energybar to energybar.Width()-Variable.(damage) when damage occurs. Hope that helps!

EDIT: Scratch that, I think I misunderstood your questin. I think you don’t want to reduce size of bar. I was thinking you had a bar behind say an open graphic that would reduce … if that makes sense.

If I understand correctly, you want to “chop” a piece out of your whole enegrybar graphic. Maybe you could make the graphic w/ 10 animations, one whole, the other less 39.4 pix, so forth, and just switch the animation to the chopped off version every HP reduction. I hope I understood correctly what you are wanting now, if not, please ignore.

Oh well I wasn’t sure what he meant either, there are so many ways to make energy bars. But what you’re saying makes sense. So I’m going to scrap what I was about to say hahah.

As far as I know, Gdevelop doesn’t allow cropping images. There are a few ways that might work for you, depending on what the health bar is like, whether it has animation or not, and whether it’s different in different sectors. Perhaps you can copy and paste the same image several times and edit each one to gradually erase pixels and use each image according to the value of the life variable. Another way could be to decompose that image into several fragments (different objects next to each other) and, depending on the value of life, make the fragments invisible as it progressively loses life.
I would choose the first option haha

How about using “Object Masking”.
You can show only some part of an image.

[quote=“[Solved] Is there such a thing as image masks (not for collision), post:1, topic:26758”]
Coming from a Flash background here - all I see when searching for masks is collision related topics - is there a way to add a mask in the Flash sense - only showing a section of the image/animation being masked?
[/quote]
Thank you all for the replies …
the most complex problem always remains …
a character who at lv 1 has 50 hp … at lv 10 he will have 150 hp …
its energy bar must always be long for example 387 pixels how do I take away the exact pixels in relation to when it has 50 hp ??? and when will they be 150 hp ???
the point is … the bar I cannot lengthen or shrink it in order to make it for example for the convenience of 400 pixels or 300 pixels … otherwise I have to change the bar …
in essence … I must have different HP on the same character and they must be represented with 394 pixels so if the 50 HP character receives 10 damage … the bar will be narrowed much more in relation to the character with 200 HP for example. …

Yo need to add 2 variables to your object say Boss0.Hp, Boss0.MaxHp
Then you make the calculation based on the width of the Sprite you’re using for the hp bar which in my case is 128px

2 Likes

In this case the options that I have mentioned are not viable haha. I can’t think of any other way at the moment. Personally, from the beginning (knowing that there are many variations in the size of the life bar by the damage received) I would have made a bar with height details and not width. In this way the pixels will not look weird when modifying the width of the bar according to the life variable. Maybe you can use other ideas to make the bar more attractive, like modifying the global color or some object effect.
I think the idea of ​​using a collision mask is when the background is fixed and not constantly changing, but maybe someone knows this better. I have never used it.

sorry only now i managed to try your solution…
weight that I’m doing something wrong… how much did you set the maxhp?? based on the pixels of the bar???
because for me, as shown in the screen, it doesn’t work…

my whidt is 251px