Legacy GM [SOLVED] Drawing custom health bar to screen size problem

T

The Last Random

Guest
Hey everyone,
having a wee bit of a problem drawing my health bar to screen_height.
here is the related code:
Code:
///obj_health_bar step event
gph = global.player_hp; //set to 100
rh = room_height; //currently 144, will resize later, needs to allow for that
hpp = //???
Code:
///obj_health_bar draw event
draw_sprite_ext(spr_hb_under,0,8,0,1,room_height,0,c_white,1); //this works as needed
draw_sprite_ext(spr_hb_over,0,8,0,1,hpp,0,c_white,1); //this is the draw event that I need help with
So the idea is that I want to draw the health bar to room height and still have it minus away depending on global.player_health, I just can't wrap my head around how to get it to draw to the room size without going over and still have it function as a health bar.
Any help will be appreciated!
Thanks.
 

Perseus

Not Medusa
Forum Staff
Moderator
Does the spr_hb_over sprite equal the room's height? In that case, a simple ratio of the current health to the maximum health (100) should be able to do what you want.
Code:
// Assuming "gph" is the variable which holds the current player health
draw_sprite_ext(spr_hb_over, 0, 8, 0, 1, gph / 100, 0, c_white, 1);
If that's not the case, we'll sadly need more information. Feel free to post screenshots of what's happening, what else you have tried, and a diagram to depict what the behavior you want actually is, otherwise it's very difficult to see where the problem lies in your method.
 
T

The Last Random

Guest
Right, so the sprite is only 4x2 in size so I am using the draw_sprite_ext to compensate, I could make the sprite room height size but then I would have to remake the sprite for when I need to change the room height.
I cannot think of any other way to explain what I need. as simply as possible: I want to have the sprite extend to the room_height while maintaining functionality as a health bar, deplete from bottom to top based on health amount. The back part is simple, just extend it to room_height, but I cannot do that with the front part, I need the health bar to extend to the bottom of the screen without going over or under.
 
T

The Last Random

Guest
Like this?
(currenthealth/maxhealth)*room_height
That works!
But it required me to change something so simple that I figured out my problem, the sprite was multiplied by the room height, the height of the sprite was 2, 2 x 144 = 288...
So yeah, I feel like I failed basic mathematics there...

Anyways, Thank you so much for that.

Does the spr_hb_over sprite equal the room's height? In that case, a simple ratio of the current health to the maximum health (100) should be able to do what you want.
This method works as well, but I needed something to allow for room size changes. Thank you either way, I was using this method until the other solution came up.
 
Top