Legacy GM Problem with health bar, really need help.

A

Alexander Olofsson

Guest
So, I'm making a RPG and I have a problem with the health bar. The more health you have, the longer the bar. But I have a background for the health, but when it increases the background gets slightly longer than the health bar, all the way up to the point where the health is as long as half of the background. And I don't want to make like, 500 different sprites for that... I hope you understand, and thanks in advance.
 
A

Alexander Olofsson

Guest
Yes
Code:
Draw Obj Event

draw_sprite_ext(spr_lifeb4,1,view_xview[0]+11, view_yview[0]+203, obj_player.maxhp/100,1,0,c_white,1)
draw_sprite_ext(spr_lifebg,1,view_xview[0]+14, view_yview[0]+203, obj_player.hpbg/100,1,0,c_white,1)
draw_sprite_ext(spr_life2,1,view_xview[0]+14, view_yview[0]+203, obj_player.hp/100,1,0,c_white,1)

//Draw Event in Draw_Stats object.

//Here's the step event in obj_player for another problem. The problem is that, when I touch the hitbox of an enemy the HPBGHeal should be 0, and it is always increasing. And when it reaches 40, then the HPBG will shrink back to the initial HP. But immediately when I lose HP, the BG shrinks.

//Lifebg

if (check >= 0)
{
    hpbgheal += 1;
}

if (hpbgheal > 40 && hp < hpbg)
{
    hpbg -= 1;
}

if (hpbg < hp)
{
    hpbg += 2;
}

if (place_meeting(x,y,par_en_hitbox))
{
    hpbgheal = 0;
}
Two problems. First the health background that increases too much.

The second problem is that when I lose health, the HPBGHEAL should be 0. And yeah I explained everything up there.
 

Simon Gust

Member
Yes
Code:
Draw Obj Event

draw_sprite_ext(spr_lifeb4,1,view_xview[0]+11, view_yview[0]+203, obj_player.maxhp/100,1,0,c_white,1)
draw_sprite_ext(spr_lifebg,1,view_xview[0]+14, view_yview[0]+203, obj_player.hpbg/100,1,0,c_white,1)
draw_sprite_ext(spr_life2,1,view_xview[0]+14, view_yview[0]+203, obj_player.hp/100,1,0,c_white,1)

//Draw Event in Draw_Stats object.

//Here's the step event in obj_player for another problem. The problem is that, when I touch the hitbox of an enemy the HPBGHeal should be 0, and it is always increasing. And when it reaches 40, then the HPBG will shrink back to the initial HP. But immediately when I lose HP, the BG shrinks.

//Lifebg

if (check >= 0)
{
    hpbgheal += 1;
}

if (hpbgheal > 40 && hp < hpbg)
{
    hpbg -= 1;
}

if (hpbg < hp)
{
    hpbg += 2;
}

if (place_meeting(x,y,par_en_hitbox))
{
    hpbgheal = 0;
}
Two problems. First the health background that increases too much.

The second problem is that when I lose health, the HPBGHEAL should be 0. And yeah I explained everything up there.
Are all sprites for the healthbars the same? What do they look like in general?
What are the hpbg and hpbgheal supposed to do?
 
A

Alexander Olofsson

Guest
HP = Hit Points (If you touch an enemy, you lose HP and so on).
HPBG = The HPBG is the same as the HP, just that if you lose HP, you know what, just look up "Dark Souls 3 Health bar" or something and look what happens when you lose hp. There's a trail behind the hp that like after you get hit, it stays there for a second then it starts to slowly deplete. It's a slightly darker shade and behind the hp.
MAXHP = The black background of the HP (A little bigger, and that's why it stretches much longer).

Hope you understand :D
 

Simon Gust

Member
Ah, I had darksouls in mind when I read the first post.
Code:
if (alarm[0] <= 0)
{
 if (hpbg > hp)
 {
  hpbg--;
 }
 else
 {
  hpbg = hp;
 }
}

if (place_meeting(x, y, par_en_hitbox))
{
 alarm[0] = 60;
}
This is how I do it. I have an alarm that is set off upon taking damage.
Once the alarm has finished, the hpbg reduces slowly until it's the same as hp.
If the hp is larger than hpbg, hpbg is set to hp.
 
The way you're calculating the sprite length is wrong. There's two ways you can have it, a fixed length bar, or a bar that gets bigger with your max hp.

Fixed length bar:
Code:
draw_sprite_ext(spr_lifeb4,1,view_xview[0]+11, view_yview[0]+203, 10,1,0,c_white,1)
draw_sprite_ext(spr_lifebg,1,view_xview[0]+14, view_yview[0]+203, 10*(obj_player.hpbg/obj_player.maxhp),1,0,c_white,1)
draw_sprite_ext(spr_life2,1,view_xview[0]+14, view_yview[0]+203, 10*(obj_player.hp/obj_player.maxhp),1,0,c_white,1)
^ The image_xscale being 10 is how long you want the bar to be at max (obviously, 10 will be 10 times the length of the original sprite, but you can put any number here depending on how long you want it to be). Also, you don't need to have the bar that represents max hp have any scaling, as the max the bar can be is 10 * the original sprite length no matter what the max hp is.

Variable length bar:
Code:
draw_sprite_ext(spr_lifeb4,1,view_xview[0]+11, view_yview[0]+203, obj_player.maxhp/100,1,0,c_white,1)
draw_sprite_ext(spr_lifebg,1,view_xview[0]+14, view_yview[0]+203, (obj_player.maxhp/100)*(obj_player.hpbg/obj_player.maxhp),1,0,c_white,1)
draw_sprite_ext(spr_life2,1,view_xview[0]+14, view_yview[0]+203, (obj_player.maxhp/100)*(obj_player.hp/obj_player.maxhp),1,0,c_white,1)
^ This one will increase the length of the bar based on the max hp the player has and the other bars should line up perfectly with the percentage of max hp the other variables are (there may be a few bugs in this code as I wrote it quickly and haven't tested it, but this is the general idea).

You have to times the division of the hp and hpbg by the maxhp to have it scale properly. If the max hp is 100 and the hp is 100, then the division gives a 1 (i.e. (maxhp/100)*1 = the full length of the original maxhp/100). If the max hp is 100 and the hp is 50, then the division gives 0.5, therefore (maxhp/100)*0.5 = half the length of the original maxhp/100 so the hp bar will be half as long as the maxhp bar. I hope this makes sense.
 
Last edited:
A

Alexander Olofsson

Guest
I tried the new code, but the result is same. The HP bar's length is determined by the MAXHP and the MAXHP's bar. So the HP cannot get any longer than that. But the problem is, just because the HP background is longer and bigger, that makes it stretch more. Here, I'll send a picture.

Here's the problem. See the HP? The background scales waay to much. https://i.imgur.com/XLH4wEo.jpg
Aaand, here are the normal sprites. https://imgur.com/z7L6yIk

Hope you understand, and that we can solve the problem :D
 
A

Alexander Olofsson

Guest
Oh, maybe this is important. The background was originally the HP, just that I made it wider and longer, so that the HP would fit in there. It only scales like this: ->.

It looks like the whole background is connected, but it isn't. It's just the HP and Stamina's bar that overlaps. I thought it looked better :D.

EDIT: You can kinda see a line between the HP and the Stamina!
 
A

Alexander Olofsson

Guest
Still need help :(

Let me sum it down again: Just because the HP background is bigger (HP BG is NOT background, MAXHP is.), it scales more and you can look at the pictures for example in my previous post"!
 

FrostyCat

Member
It scales too much because your background has both regions that are scaled (the main bar region) and regions that aren't (the margins). The more you scale, the more the non-scaled regions fall behind. You need to break up your background and draw the scaled and unscaled parts separately.
 
Top