Drawing On The GUI Layer

Halas

Member
Is there a way to create an object based on the coordinates of the GUI layer?

What I am trying to do:

For my character information screens, I am attempting to create an Obj_Slot that would be interactable with the player. (To place an item(weapon))
The Menu ( For example, Equipment Screen with slots to equip a weapon) draws on the GUI Layer with OBJ_HUD
The Inventory Slot is drawn with the OBJ_INV_CONTROLLER

I am having difficulties to draw both of these at the same time.
I am not sure how to find the correct X and Y locations to draw the Inventory Slot where it shows on the Equipment Screen.

Thanks in advance

CHAR_EQUIP.png
 

Roldy

Member
Need more information.

But I'll make some assumptions:

For your 'Equipment Screen' you are drawing 'slots.' Lets say they are rectangles to mark where the slot is on the screen. You do this during DRAW GUI of OBJ_HUD.
You also want to draw the equipment that is in that slot at the same location. Currently you want to do that with OBJ_INV_CONTROLLER. I am assuming that is because that object has the item information.

What I would suggest is to have OBJ_HUD do all the drawing. Draw the rectangle for the slot, then draw the sprite for the item in the same place. OBJ_HUD can retrieve whatever information it needs about the inventory or items from OBJ_INV_CONTROLLER.

If that doesn't make sense, or doesn't work for you. Then I would suggest you post your code and explain in more detail about what you are wanting to do.
 

Halas

Member
The OBJ_INV_CONTROLLER handles all the information for items, including the sprites for the items.
OBJ_SLOT handles the actual holder of the info, so the player knows where the item is, and how/if it is equipped. This feeds into OBJ_INV_CONTROLLER.
I am letting OBJ_HUB handle the drawing of the equipment screen.

GML:
OBJ_HUD

TOGGLED BY KEY PRESS:

USER EVENT:

/// @description Toggle Equipment Page
//This Handles the Drawing of the Equipment Screen

if not equip_page {
    equip_page = true;
} else {
    equip_page = false;
}

//This Handles the creating of the inventory system
if(obj_inv_controller.inventory_is_open)
    {
    event_user(INV_CON_EVENTS.close_inv);
    }
    else {
    event_user(INV_CON_EVENTS.open_inv);
    }

DRAW GUI:

#region Equipment Screen

if equip_page = true
    {   
        Player_stat_check();
        ///Draw equip page
        draw_sprite(spr_ex_panel_equipment1, 0, menu_x, menu_y)   
    }                   
#endregion


OBJ_INV_CONTROLLER

USER EVENT:

if(inv_open) { exit; }

[B][U]NEED HELP:[/U][/B]
panel_open(global.inv_equipment, obj_inv_equip, X, Y, layer);

inv_open = true;
For panel_open(global.inv_equipment, obj_inv_equip, X, Y, layer)

How do I find the X and Y coordinated to match the GUI Layer on the Equipment Screen?
 

Roldy

Member
How do I find the X and Y coordinated to match the GUI Layer on the Equipment Screen?
Well it looks like your equipment screen is just one big sprite, spr_ex_panel_equipment1, drawn at (menu_x, menu_y) during DRAW GUI.

IF that is the case you would need to know where , in pixels the 'slots' are in that image and offset them by that much... e.g. slotX = menu_x + offset_of_slot_in_sprite_x. Something like that.

If you are wanting OBJ_INV_CONTROLLER to know menu_x, menu_y from OBJ_HUD, then just reference them.

GML:
var _panelX = OBJ_HUD.menu_x;
var _panelY = OBJ_HUD.menu_y;

panel_open(global.inv_equipment, obj_inv_equip, _panelX, _panelY, layer);
 
Last edited:

Halas

Member
This isn't working for me.

How can I check if this panel is created and where it is created?
 
Last edited:

samspade

Member
Is the image you posted in the original post a single image? And then you want an another sprite (such as the sprite of the equipment) overlayed on top of it? If you're using a single sprite for the image, what is that sprites origin and what is the origin of the sprites that you want to overlay?
 

Halas

Member
I would like to draw the OBJ_SLOT above the Equipment Screen.

I have a red dot to point where the OBJ_SLOT is. The dimensions are only 42x42. The origin points would still be noticed if it was in the area. (Tohelp with testing)

Unless its drawing beneath it and I can't see. (How do I fix that?)
 

woods

Member
if its being drawn beneath..
could you draw obj_slot in the end step so it draws after the equipment screen(this makes it drawn on top of?)
 

Yal

šŸ§ *penguin noises*
GMC Elder
I have a red dot to point where the OBJ_SLOT is. The dimensions are only 42x42. The origin points would still be noticed if it was in the area. (Tohelp with testing)

Unless its drawing beneath it and I can't see. (How do I fix that?)
Have the same object draw everything, so you can control the order. You can use with(thatOtherObject){event_perform(ev_draw,0)} style loops to force other objects to draw in your draw event if it's easier to split up drawing code - this works even if the objects you're with-ing are invisible (since "visible" only affects automatic drawing).

Instead of drawing debug points, try drawing debug lines (starting at the center of the screen). That way, it's easy to tell if they're going to where you want them to, or offscreen into the void. If the lines are gradient-colored you can also tell how far away the endpoints are based on if you can see the gradient change or not.
 

Halas

Member
Have the same object draw everything, so you can control the order. You can use with(thatOtherObject){event_perform(ev_draw,0)} style loops to force other objects to draw in your draw event if it's easier to split up drawing code - this works even if the objects you're with-ing are invisible (since "visible" only affects automatic drawing).

Instead of drawing debug points, try drawing debug lines (starting at the center of the screen). That way, it's easy to tell if they're going to where you want them to, or offscreen into the void. If the lines are gradient-colored you can also tell how far away the endpoints are based on if you can see the gradient change or not.
Thanks, this helped me solve the issue.

When staring at a problem for so long, the answer always seems the simplest.
 
Top