Best way to create a hud for a RTS game

Hello everyone,

I try to improve my HUD system for my RTS.
Actually i use object to build my GUI.

For exemple i click on the button "energy" (image below) :

Untitled.png
It creates more objects on my GUI :
Untitled2.png

This is my code, if i click in the button energy :
GML:
if mouse_check_button_pressed(mb_right)
{active = false}

if (active = true && !instance_exists(obj_energy_cat_1))
    {
        ///
    instance_create_depth(10,750,-1,obj_energy_cat_1)
    instance_create_depth(117,750,-1,obj_button_panel)//IF I CLICK HERE FOR EXEMPLE
        ///
    instance_create_depth(10,800,-1,obj_energy_cat_2)
    instance_create_depth(117,800,-1,obj_button_wire)
    instance_create_depth(181,800,-1,obj_button_battery)  
        ///
    instance_create_depth(10,850,-1,obj_energy_cat_3)
    instance_create_depth(117,850,-1,obj_button_lamp)
   
   
    }
if active = false
    {
        ///
    instance_destroy(obj_energy_cat_1)
    instance_destroy(obj_button_panel)
        ///
    instance_destroy(obj_energy_cat_2)
    instance_destroy(obj_button_wire)
    instance_destroy(obj_button_battery)
        ///
    instance_destroy(obj_energy_cat_3)
    instance_destroy(obj_button_lamp)
    }

Finally, if i click on my "obj_button_panel" i can now put my solar panel on the map.

As you can see it's heavy, i need to put the new coordinates for each buttons and it's more and more complicated because i will have many object that i can build.

Can you help me?
 
Personally I use objects for buttons. I have one main button object that does all the hovering, clicking, etc and I just have each button execute a script when clicked.this was I never have to manually set coords as it's related to my sprite mask.
 
Personally I use objects for buttons. I have one main button object that does all the hovering, clicking, etc and I just have each button execute a script when clicked.this was I never have to manually set coords as it's related to my sprite mask.
My problem is that

My problem is i can't have 100 buttons on the screen.
So i classify them in categories.
Actually if i click on ENERGY button i create more buttons on the screen to choose what i want to build.
 

Nidoking

Member
You could trim that down a bit by, say, putting the buttons you need to create into a data structure in the button that creates them - so, for example, give the obj_button_panel a set of arrays, lists, or a single grid that contains each button it needs to create and their x and y coordinates, then loop through that structure and create the buttons. You could then adjust those buttons or their placements by modifying the data structure in the create event. It's still a lot of code, but the common elements would be a lot cleaner.
 
Yes you would not create all buttons at once but like Nidoking is saying you need to group buttons together and have certain buttons that act as a trigger for creating the other gui buttons. If you do it like that then you shouldn't need a 100 buttons on screen at once.
 
Top