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

GameMaker Mouse Enter Event and place_meeting not playing nice in the GUI

P

Pepasone

Guest
I'm a bit confused by this.

I have buttons as objects drawn in my GUI. I have two very simple events; Step, Mouse Enter

In the Step event I just check if there is a place_meeting with the cursor, this triggers just fine. In the Mouse Enter event I just display a debug message "Entered", it will not trigger. The part that is confusing is that they both the Mouse Enter event and the place_meeting function both utilize the collision mask of said object.

For this reason I do not understand how the place_meeting function can be true, but the Mouse Enter event cannot.

Any thoughts?

Step Event
GML:
// We aren't hovering, don't draw the overlay
if !place_meeting(x, y, obj_cursor_menu)
{
    image_index = 0;  
}

// We are hovering, draw the overlay
else
{
    image_index = 1;
   
    // Check for a click
    if mouse_check_button_pressed(mb_left)
    {
       
    }
}
Mouse Enter
GML:
show_debug_message("Entered");
 

FoxyOfJungle

Kazan Games
You are doing it incorrectly, place_meeting() is for collisions, do not use this for interface buttons, I suggest and recommend using point_in_rectangle() in the Draw GUI event that will work perfectly!
Also look at the device_mouse_x_to_gui() and device_mouse_y_to_gui() functions.
 
P

Pepasone

Guest
How is checking for a collision with my cursor object an incorrect use of place_meeting?
 
P

Pepasone

Guest
You are doing it incorrectly, place_meeting() is for collisions, do not use this for interface buttons, I suggest and recommend using point_in_rectangle() in the Draw GUI event that will work perfectly!
Also look at the device_mouse_x_to_gui() and device_mouse_y_to_gui() functions.
My cursor object is already set to window_mouse_get_x and window_mouse_get_y, window is the same size as the GUI.
 

FoxyOfJungle

Kazan Games
Now I was confused by your real question, do you just want to know if the mouse is on top of a normal object located in the room? If so, just do:

GML:
if place_meeting(mouse_x, mouse_y, object_index)
{
    // Check for a click
    if mouse_check_button_pressed(mb_left)
    {
      
    }
    image_index = 1; 
}
else
{
    image_index = 0;
}
If you are using the cursor as an object, just replace mouse_x and y with the coordinates of the mouse object.
 
P

Pepasone

Guest
Now I was confused by your real question, do you just want to know if the mouse is on top of a normal object located in the room? If so, just do:

GML:
if place_meeting(mouse_x, mouse_y, object_index)
{
    // Check for a click
    if mouse_check_button_pressed(mb_left)
    {
    
    }
    image_index = 1;
}
else
{
    image_index = 0;
}
If you are using the cursor as an object, just replace mouse_x and y with the coordinates of the mouse object.
I think you are confused and maybe I did a poor job of explaining.

The hover functionality works as expected. If I hover the button, it swaps the image index no problem. The issue is, that the Mouse Enter event does not trigger period. The question is, if place_meeting is based on the collision mask AND Mouse Enter is ALSO based on collision mask, how can one trigger, but not the other?
 

FoxyOfJungle

Kazan Games
I think you are confused and maybe I did a poor job of explaining.

The hover functionality works as expected. If I hover the button, it swaps the image index no problem. The issue is, that the Mouse Enter event does not trigger period. The question is, if place_meeting is based on the collision mask AND Mouse Enter is ALSO based on collision mask, how can one trigger, but not the other?
I think this is happening because of a mistake, and it is related to obj_cursor_menu. the Mouse Enter event is triggered when the OS cursor collides with the object's bounding box, in your code, you check the collision between two objects, not an object and a cursor. That's what I understood with your information. Can you explain what's in the obj_cursor_menu? Or how is it done (code)?
 

samspade

Member
I'm a little confused as to either works since I see two problems.

The first problem is what @FoxyOfJungle just said which is that place_meeting checks for a collision with an instance. So saying place_meeting(x, y, obj_cursor_menu) would only work if you had an instance tracking the cursor. However, it seems like you actually do have some type of object which tracks the mouse. Otherwise, you would want position_meeting(mouse_x, mous_y, object) to know if the mouse is over the object.

The second problem is that GUI space and room space are not the same. The only way they would overlap is if both your room, view, and gui were all the exact same size. Since the mouse_enter/mouse_leave events use the the position of an instance in room space, since it doesn't sound like you're not actually moving your instance around in room space (e.g. by offsetting the view) mouse enter and mouse leave shouldn't work. You would want position_meeting(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), object) to know if there was an overlap in gui space.
 
Top