• 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!

Optimized "menu" [beginner level]

Zaksley

Member
Hi guys,
I did a clear and cool menu but I'm not sure if I did it right. It's my first game and I'm here to learn, I don't care if something works, I'm prefer learn to code right.

Let's talk now about my menu. I saw some youtubers create their menu using a lot of objects like 4 boxes for the commands (WASD) or a box for the name of the player. In my game, I used the draw event to get some boxes and because I don't know how to check the "collision" between the mouse and something that I draw, I used a lot of time something like this :

Code:
        //Mouse sur les boutons SHIPS
    if (mouse_y >= room_height/2 - shipbutton_h/2) && (mouse_y <= room_height/2 + shipbutton_h/2)
    {
        for(var i = 0; i <= 2; i++)
        {
            var xx = room_width/4 + (shipbutton_w + shipbutton_spacing) * i   
           
            if (mouse_x >= xx - shipbutton_w/2) && (mouse_x <= xx + shipbutton_w/2)
            {
                ship_index = i;
               
                    if (mouse_check_button_pressed(mb_left))
                    {
                        ship_select = ship_index;   
                        obj_game.alarm[3] = 1; 
                    }
           
                break;
            }
            else
            {
                ship_index = -1;   
            }
It's just an exemple but here you can see I use " if mouse_x is between this x1 and this x2, ..."
I don't know if it's a good idea.

So, the solution seems to use some objects. But, and here is my problem : If I use objects, How can I use the "things" that I draw. I can create some sprite for the boxes. But I created a button PLAY with a very cool writing font. How can I create a sprite from this font ?

For now, I just "create" a box that surrounds approximatly this button.

Drawning event
Code:
//Button PLAY 
   
        draw_set_font(font_ASTEROID_giant);
   
        draw_set_color(make_color_rgb(167, 17, 1));   
        if(mouse_on_PLAY)
        {
            draw_set_color(make_color_rgb(240, 128, 128))   
        }
   
        draw_text(room_width/2, room_height*4/5, "PLAY" );
Step event (obj_menu)

Code:
    var play_x1 = room_width/2 - 135;
    var play_x2 = room_width/2 + 135;
    var play_y1 = room_height*4/5 - 40;
    var play_y2 = room_height*4/5 + 40;

   
    if (mouse_x >= play_x1 && mouse_x <= play_x2) and  (mouse_y >= play_y1) && (mouse_y <= play_y2)
    {
            mouse_on_PLAY = true;
       
            if(mouse_check_button_pressed(mb_left))
            {
                room_goto(room_game);
            }
    }
I'm pretty sure everything I said is not very clear, but I hope you can help me. Thank you very much.
 
I'd stick with the way you are currently doing it. It's how I handle all my menus. It keeps everything in one place, is easy to adjust, and makes stacking layers and such so much easier.
 

Zaksley

Member
Alright so I shouldn't change ? That's very cool, I was like "I'm sure i'm doing something very bad and ugly" lmao :D
 
Top