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

Windows [SOLVED] Mouse hover breaks on pause menu when entering larger room

A

Accredited Design

Guest
Hello everyone, this is my first post only because this one really has my brain giving off smoke.
So, the current structure I have is an intro room where you press a key to move on. This goes to the next room which is a just text scroller which gives a story. When it's done it goes to the first actual game room. The first two intro rooms are set to 1280x720. The 3rd room (actual game) is 10,000x10,000 using a 1280x720 view[0] centered on the player object. The game rooms are persistent, as well as the player object. This goes for the next room/level after it, and all future subsequent levels/rooms which I'll probably increase in total room size eventually.
The trouble I have is that I have a menu accessible via "ESC" key at any time. It is an object "obj_menu_controller" plopped into each room which merely watches for the ESC key and if pressed creates the menu object "obj_main_menu". It works perfectly both windowed and fullscreen in the first two 1280x720 rooms. When entering the 3rd room at 10,000x10,000 the menu still pauses the game and appears, but the mouse hovers break, rendering the menu useless. I assume it's because it's looking for mouse hover who knows where in the whole of the 10,000x10,000 room, but perhaps that's not the issue?? Here's my setup for the obj_main_menu:

CREATE EVENT:
Code:
instance_deactivate_all(true);
audio_pause_all();
DRAW GUI EVENT:
Code:
display_set_gui_size(view_wview[0],view_hview[0]);
draw_sprite(spr_main_menu, 0, 640, 360);

var _x,_y;

if window_get_fullscreen() {
    _x = display_mouse_get_x() / display_get_width();
    _y = display_mouse_get_y() / display_get_height();
} else {
    _x = window_mouse_get_x() / window_get_width();
    _y = window_mouse_get_y() / window_get_height();
}

x = view_xview[0] + (view_wview[0] * _x);
y = view_yview[0] + (view_hview[0] * _y);

//draw the resume button
if point_in_rectangle(x, y,460,157,818,242)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_resume, hover, 640, 200);
if (mouse_check_button(mb_left)) && (hover=1)
{
    instance_destroy();
    audio_resume_all();
}

//draw the restart button
if point_in_rectangle(x, y,460,286,818,372)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_restart, hover, 640, 330);
if (mouse_check_button(mb_left)) && (hover=1)
{
    game_restart();
}

//draw the options button
if point_in_rectangle(x, y,460,416,818,502)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_options, hover, 640, 460);
if (mouse_check_button(mb_left)) && (hover=1)
{
    instance_destroy();
    instance_create(x,y,obj_options_DEP);
}

//draw the quit button
if point_in_rectangle(x, y,460,547,818,632)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_quit, hover, 640, 590);
if (mouse_check_button(mb_left)) && (hover=1)
{
    game_end();
}
DESTROY EVENT:
Code:
instance_activate_all();
PRESS ESCAPE EVENT:
Code:
instance_destroy();
audio_resume_all();
Here's a screenie of the menu working in the first 2 rooms:


And a screenie of the "broken" menu in the 3rd and on rooms:


Any ideas on what could cause the mouse hover/sprite change to not work in the 3rd (huge) room? Thanks very much in advance for any guidance you may have to offer.
 
A

Accredited Design

Guest
Thanks rIKmAN, I'm admittedly new to GML, but not to coding in other languages, so I'm learning (quickly) as I go. I see now what device_mouse_x_to_gui and device_mouse_y_to_gui do in a book sense, but how would I apply it in practice to the Draw GUI even code I referenced? In place of the "if point_in_rectangle" statements? For instance, how should this block look? Thanks!

Code:
//draw the resume button
if point_in_rectangle(x, y,460,157,818,242)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_resume, hover, 640, 200);
if (mouse_check_button(mb_left)) && (hover=1)
{
    instance_destroy();
    audio_resume_all();
}
 
Last edited by a moderator:

rIKmAN

Member
Thanks rIKmAN, I'm admittedly new to GML, but not to coding in other languages, so I'm learning (quickly) as I go. I see now what device_mouse_x_to_gui and device_mouse_y_to_gui do in a book sense, but how would I apply it in practice to the Draw GUI even code I referenced? In place of the "if point_in_rectangle" statements? For instance, how should this block look? Thanks!
Code:
//draw the resume button
if point_in_rectangle(x, y,460,157,818,242)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_resume, hover, 640, 200);
if (mouse_check_button(mb_left)) && (hover=1)
{
    instance_destroy();
    audio_resume_all();
}
Same boat as me in terms of GML and GM in general - never used it but couldn't resist at $15 during the Humble Bundle and thought even if I only used it to prototype some ideas it would be worth it - so yeah I'm no expert either!

In a create event call display_set_gui_size once to set the gui to whatever resolution you are targeting (ie. 1024x768) - you can also use display_set_gui_maximise for variable resolutions).
Code:
display_set_gui_size(1024, 768)
I'm not sure how your other code works in terms of x/y, offsets etc, but to get the menu on the GUI Layer use:
Code:
//draw the resume button
if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0),460,157,818,242)
{
    var hover=1;
}
else
{
    var hover=0;
}
draw_sprite(spr_button_resume, hover, 640, 200);
if (mouse_check_button(mb_left)) && (hover=1)
{
    instance_destroy();
    audio_resume_all();
}
Using the mouse_x/y_to_gui functions means it always falls within the boundaries of the resolution you set with display_set_gui_size and I think your problem is that your x/y values are taking into account the room x/y and so are offset and checking the wrong positions.

Hopefully that works anyway, but not tested.
 
A

Accredited Design

Guest
Thanks rIKmAN, It works now. I've found a far simpler solution.
I deleted part of the code, and merely changed the x= and y= to device_mouse_"xy"_to_gui
So, the beginning of my Draw event now looks like this:
Code:
display_set_gui_size(view_wview[0],view_hview[0]);
draw_sprite(spr_main_menu, 0, 640, 360);
x = device_mouse_x_to_gui(0);
y = device_mouse_y_to_gui(0);
Much cleaner. Thanks again!!
 
Last edited by a moderator:

rIKmAN

Member
Thanks again rIKmAN, I shouldn't have, but I edited my previous reply in-place because I found the solution, and it's very quick and easy. See my last post above. Thanks so much.
You don't need to call display_set_gui_size() every step in your draw event, just call it once in a Create Event to set it and that's it.

No problem, glad it's working!
 
A

Accredited Design

Guest
You don't need to call display_set_gui_size() every step in your draw event, just call it once in a Create Event to set it and that's it.
Ahh, gotcha. Thanks for that too.
 
Top