GML Making HUD follow the views

RangerX

Member
Alternatively, how do you position the drawing of your HUD? If you don't draw it according view's coordinates, of course it will draw according the room's coordinate.
 
D

Diveyoc

Guest
If you create a Draw Gui event in your player object, and add these draw strings, it will be very useful in determining where your GUI x,y, positions are for drawing out your huds and what not.
If your room height is small, change 830 to something smaller. You can use this for game development and just delete these strings when the game is finished.

draw_set_color(c_white);
gui_x = display_mouse_get_x();
gui_y = display_mouse_get_y();
draw_text(10,830, "GUI Mouse X-Y:");
draw_text(140,830, string_format(gui_x,4,0)+","+string_format(gui_y,4,0));
 
P

pixelRaid

Guest
It's a bit more complex than just text, I have sprites involved in the GUI, which in turn are governed by a code. I have two kinds of ammo my character shoots, one is a small and missile with a large clip and the other is bigger with a single missile in the clip. I have two pairs of objects. Each pair has one object for having ammo in the clip and the other object to denote reloading. So total four objects. The key-mappings for each of these missiles are coded on the player object. Just by writing it down I feel I've created a mess. But I'd appreciate a way out.

To simplify things a bit for me, I had set up two variables, one for small missiles and the other for the bigger ones. There value being 1 means, there is ammo in the clip, 0 means reload. These variables too are set in the player object. I'm using them on the sprite objects for each of the states of clips. For example, if the variable for small missiles is 0, the loading object for the small missile is drawn using the draw GUI and if it's 1, destroy instance.

This is my current setup and it's not working. I hope it makes sense.
 
P

pixelRaid

Guest
If you create a Draw Gui event in your player object, and add these draw strings, it will be very useful in determining where your GUI x,y, positions are for drawing out your huds and what not.
If your room height is small, change 830 to something smaller. You can use this for game development and just delete these strings when the game is finished.

draw_set_color(c_white);
gui_x = display_mouse_get_x();
gui_y = display_mouse_get_y();
draw_text(10,830, "GUI Mouse X-Y:");
draw_text(140,830, string_format(gui_x,4,0)+","+string_format(gui_y,4,0));
Can you explain me the code?
 
P

pixelRaid

Guest
Alternatively, how do you position the drawing of your HUD? If you don't draw it according view's coordinates, of course it will draw according the room's coordinate.
How do I draw the HUD according to room's coordinates? Using Draw GUI event?
 

RangerX

Member
To position your Hud according to the view. It needs to be same position as the view + the desired offset.
Per example, an offset of 120 pixels:

obj_Hud.x = view_xview + 120;
obj_Hud.y = view_yview +120;
 
P

pixelRaid

Guest
To position your Hud according to the view. It needs to be same position as the view + the desired offset.
Per example, an offset of 120 pixels:

obj_Hud.x = view_xview + 120;
obj_Hud.y = view_yview +120;
I revamped the GUI of the game because I had messed up the whole thing. So now, when the player is out of clip for the smaller missiles, an object is created which is a sprite mentioning "Reloading", same for the bigger missile. I was able to create an instance of the object relative to the view. But the instance does not follow the view, it's static. How do I move the instance?

This how the missile clip and "Reloading" object is working:

(The position of the instance, relative to the view, is mentioned inside the Create Instance action)

This is for the smaller missile:

ship_left_click.PNG

This is for the bigger missile:

ship_right_click.PNG
 
Top