• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How to make healtbar to stay in right corner? [solved]

M

Mikapo

Guest
Hey,
I would like to code the hp bar to stay at the top right but I don't know how to make it work.
Any help.

My code is:
draw_sprite(healtbar_empty,1,obj_player.x-380,obj_player.y - 170);
draw_sprite_ext(healtbat_full,1,obj_player.x-380,obj_player.y - 170,obj_player.hp/25,1,0,c_white,1);
draw_sprite(healtbar_border,1,obj_player.x - 380,obj_player.y - 170);

I am using gamemaker studio 2.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Use the Draw GUI event to draw it, then you draw at screen coordinates (which are always the same no matter the position of views etc) rather than room coordinates.
 

Perseus

Not Medusa
Forum Staff
Moderator
What exactly is the problem with that code? That's the most important part of the problem you should share information about when creating a topic here. Also, do you want the healthbar to stay in the top-right corner of the room or that of the player?

From what I can tell, it's probably the former. In that case, you can make use of the Draw GUI event. Note that unlike the regular Draw events, you need on-screen coordinates in that event. Check out the manual for further reference.
 
D

dan_j

Guest
Hi there, I'm no expert but looking at your code you've specified your x and y to be the players x and y position, hence probably why it's moving around? If it's the top right corner of the screen you're after then you're probably best using room width with some padding for x and a number for the y.
eg;
draw_sprite(healtbar_empty,1,room_width - 250, 70);
 
Top