[SOLVED] Health bar not displaying correctly

My HP bar isn’t showing right. (See attached) It’s set for:

Do =GlobalVariable(HP)/GlobalVariable(MaxHP) to the width's scale of HPBar

The attached image shows what it gives with 100 HP / 100 MaxHP… it should be filled. Am I doing this wrong or is there a better way to do it?
hpbar.png

It should work. :confused:

Are you sure the value of hp and maxhp is the same and the health bar does fit/fill the background when it not scaled (scale = 1) ?

I’m not too sure what else could be the problem, the only thing I can think of is hp is not equal to maxhp or the background and health bar does not fit. Have you changed the scale/size of the health bar in the editor to fit? Because if you did, that could be the problem.

Yeah, the first thing I did was check everywhere the variables are mentioned, and made sure Custom Size was unchecked for the sprites. They are from the Kenney Roguelike pack, scaled to 200% in Tiled, so the images themselves are the same size. I used a text object to show “Current HP / Max HP” and it shows the right numbers, the sprite just isn’t scaling with the numbers for some reason. As a test, I changed the HP to be 150 / 100 and the fill bar was only a few pixels bigger than the outline. The only mention of the HP fill bar in the events editor is to set the scale to HP/MaxHP.

This is why I’m lost. Everything points to “it should work”, but it doesn’t. I’ll probably have to use a text object instead and just show the numbers.

I also have a vertical action bar using the same tileset that fills based on GlobalVariable(Speed)*TimeDelta() and it works properly, except it fills from top to bottom and I can’t figure out how to do bottom to top… but it does fill all the way to 100%.

I don’t think you should drop health bar and use ugly numbers instead, there must be something causing the problem.
I have just created a small example and it works, take a look if you want

hp background is 100 pixels wide and 20 pixels high. The border of the background takes 4-4 pixels form width and height so the actual hp bar is 96 pixels wide and 16 pixels high to fit perfectly on the background.

Finally, in the events I’m make sure if the hp is less than 0, set it to 0 if greater then maxhp than set it to maxhp.
For example if the player got only 2 health left, but the enemy cause 3 damage, the health goes in to -1 or in case the player got 98 health and the health pack gives 3 health it makes the hp to go above maxhp which could screw up the health bar and also the gameplay.

It very simple really, take a look:
hpbar.zip (3.74 KB)

Try to change the position of the origin point :slight_smile:
Sprites always scales from the origin points, if it on left and you scale it on the X axes, the sprite scales from left to right if it on the right, it is going to scale from right to left. If you want it to scale from bottom to top, put the origin point on the bottom and make sure you scale it on the Y axes :slight_smile:

I just tried removing the objects (fill and outline) and cleared the events editor of any references to them, started from scratch with the health bar and it works now. There must have been something I was overlooking when trying to find the problem.

I could have sworn I tried that, but it must have been on something else because it worked perfectly. It also helped me solve a different, unrelated, problem too. Thanks.

As a reference for anybody that’s interested, here’s a screenshot of how I did this.

No other reference to the HPFill and the only references to the HP variables are removing for attacks, adding for health packs/potions (haven’t gotten that far yet), and on enemy creation (can’t let a Bat, Slime, and Spider all have the same HP, right?).

Hey,

Just wanted to let you know I encountered a similar issue.
Simply Deleting the object (not even the code/ references) fixed it for me.

I tried manually changing the orgin point myself and a bunch of stuff, but it didn’t help. Simply removing and re-adding though, fixed it instantly. I banged my head against the same wall for like an hour on something so stupid and such a simple solution fixed it. Ughhh