Clickable options refuse to be clicked on

S

skaiiwalker

Guest
I'm trying to make clickable text-based menu options. I've made it so that when the mouse is in the rectangle surrounding the text, it will change color and highlight. I tried using the same method in a Left Mouse Down event, where if the mouse is clicked while the mouse is in the text rectangle it will do that menu option's task. But for some reason, no dice. Could somebody else that's more experienced in gamemaker let me know what I might be doing wrong?

Text Object Left Mouse Down Event:
GML:
if (point_in_rectangle(mouse_x, mouse_y, x, y, x + string_width(optionText), y + string_height(optionText)))
{   
    switch (menuNum)
    {
        case 0: menu_playGame();
            break;
        case 1:
            menu_settings();
            break;
        case 2:
            menu_quit();
            break;
        case 3:
            menu_return();
            break;
    }
}
Script scr_titleMenuOptions:
GML:
//on startup
function menu_buildMenu()
{
    numOptions = 3;
    for (var i = numOptions - 1; i >= 0; i--)
    {
        menuOptions[i] = instance_create_layer(obj_titleMenuCreator.x, obj_titleMenuCreator.y + (i * 50), "layer_menu", obj_titleMenuOption);
    }

    menuOptions[0].optionText = "Play game";
    menuOptions[1].optionText = "Settings";
    menuOptions[2].optionText = "Quit";
    
    for (var i = 0; i < numOptions; i++)
    {
        menuOptions[i].menuNum = i;
    }
}


//menu option 0
function menu_playGame()
{
    room_goto(rm_playSpace);
}


//menu option 1
function menu_settings()
{
    instance_destroy(obj_titleMenuOption);
    numOptions = 1;
    for (var i = numOptions - 1; i >= 0; i--)
    {
        menuOptions[i] = instance_create_layer(obj_titleMenuCreator.x, obj_titleMenuCreator.y + (i * 50), "layer_menu", obj_titleMenuOption);
    }

    menuOptions[0].optionText = "return";
    
    for (var i = 0; i < numOptions; i++)
    {
        menuOptions[i].menuNum = i + 3;  //adding 3 because there are three options in the original menu
    }                                     //if more are added, this number should go up
}

//menu option 3
function menu_return()
{
    instance_destroy(obj_titleMenuOption);
    menu_buildMenu();
}

//menu option 2
function menu_quit()
{
    game_end();
}
 

WilloX

Member
The mouse_down event only triggers if the mouse is colliding with the sprite mask afaik. Maybe try the global_mouse events. Or the step event with and additional
GML:
if mouse_check_button_pressed(mb_left)
    {
    ...
    }
 
S

skaiiwalker

Guest
The mouse_down event only triggers if the mouse is colliding with the sprite mask afaik. Maybe try the global_mouse events. Or the step event with and additional
GML:
if mouse_check_button_pressed(mb_left)
    {
    ...
    }
That fixed it! Thanks!
 
Top