GameMaker How to make HUD?

B

BlueCat6123

Guest
I'm trying to make a health bar object that follows the view but
Code:
x = camera_get_view_x(view_camera[0])
y = camera_get_view_y(view_camera[0])
is really choppy and doesn't follow the view as fast as the view moves.

I put the health bar in a layer above everything and used the code above on it.
 
M

Meowanator

Guest
I'm trying to make a health bar object that follows the view but
Code:
x = camera_get_view_x(view_camera[0])
y = camera_get_view_y(view_camera[0])
is really choppy and doesn't follow the view as fast as the view moves.

I put the health bar in a layer above everything and used the code above on it.
Just put the code from the Draw Event to the Draw Gui Event. Also remove the camera_get_view code.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
To explain... The GUI layer is a layer that is drawn over the main draw canvas, and so it isn't affected by views. This means that you can simply draw at absolute positions from (0, 0) to (gui_width/gui_height). The width and the height of the gui can be set through code, so you can have complete control over what you want to draw, and where, without worrying about offsets for the view. To sue the GUI layer, simply add draw code into the Draw GUI event, and check the manual for more information about it. http://docs2.yoyogames.com/index.ht...2_interface/1_editors/events/draw_events.html
 
B

BlueCat6123

Guest
Just put the code from the Draw Event to the Draw Gui Event. Also remove the camera_get_view code.
Yeah, that worked, but I do have a fade object for going between rooms and I'd like the health bar to be under the fade. Do you know if I can do anything like change the depth of the drawn bar?

Thanks!
 
M

Meowanator

Guest
Yeah, that worked, but I do have a fade object for going between rooms and I'd like the health bar to be under the fade. Do you know if I can do anything like change the depth of the drawn bar?

Thanks!
For the fade object, you could put draw_self(); in the Draw Gui Event
 
O

Outseidr

Guest
in draw event

var hper;
hper = (hp / maxhp) * 100;
draw_rectangle(__view_get( e__VW.XView, 0 ) + 100,__view_get( e__VW.YView, 0 ) + 66, (__view_get( e__VW.XView, 0 ) + 200) + ((hper - 100)),__view_get( e__VW.YView, 0 ) + 68, false)


that bad boy will even turn your healthbar into a percentage value so it wont grow or shrink while the max increases
 

Kyon

Member
in draw event

var hper;
hper = (hp / maxhp) * 100;
draw_rectangle(__view_get( e__VW.XView, 0 ) + 100,__view_get( e__VW.YView, 0 ) + 66, (__view_get( e__VW.XView, 0 ) + 200) + ((hper - 100)),__view_get( e__VW.YView, 0 ) + 68, false)


that bad boy will even turn your healthbar into a percentage value so it wont grow or shrink while the max increases
Looks like someone converted his GMS1 file to GMS2.
 
O

Outseidr

Guest
Looks like someone converted his GMS1 file to GMS2.
I sure did lol. Ive been using GM for like 15 years, the way it changes its code always amazes me. Especially with gms2 great conversions, ive not had an issue yet
 
T

trentallain

Guest
Yeah, that worked, but I do have a fade object for going between rooms and I'd like the health bar to be under the fade. Do you know if I can do anything like change the depth of the drawn bar?

Thanks!
You could use draw_clear_alpha in the draw GUI event after the health bar code and use a variable to fade it.

(think of it as if you had drawing 1 and then later you did drawing 2 on the same page, drawing 2 would be drawn at the higher depth because it's over the top of drawing 1).
 
Top