Windows Mouse Enter event doesn't work with views

Hello there,

I'm new to GMS2 so this is my first approach to the event Draw GUI.

I used that event to draw my GUI (basically a rectangle with some buttons in it). Every button (also drawn with Draw GUI) geh highlighted when event Mouse Enter occurs (and highlight's off on event Mouse Leave). It used to work with the normal Draw event but now, since Draw GUI leaves the same old cordinates (even if it's drawn into the view), if my viewport isn't in the start position, the buttons are not working properly anymore (everything is translated, ex: if my button is on the right border of the window, it works until I don't move the view; if that, my mouse cursor needs to stay closer to the center in order to activate that right-border button , meaning the actual position of it doesn't change, as expected).

How should I solve this?

What if I want to just use the Draw event but giving view_xview (and view_yview) coordinates like I used to do in Game Maker 8?
 
H

Homunculus

Guest
As you correctly stated, the problem is that the sprite bounding box (used by the mouse enter and leave events) is related to the room coordinates, but you draw it in GUI coordinates. This means you can't rely on those events for a mouse hover.

It's pretty easy to fix though, just do the same with code and mouse to gui coordinates:

GML:
var _mouse_x = device_mouse_x_to_gui(0);
var _mouse_y = device_mouse_y_to_gui(0);

if(position_meeting(_mouse_x, _mouse_y, id)) {
    //mouse is over
}
 
Top