This function locks the mouse cursor in place inside the window, and makes it invisible.
Mouse movement can still be read through the functions window_mouse_get_delta_x and window_mouse_get_delta_y.
The cursor is set back to its previous "visible" state when mouse lock is disabled again, i.e. when the function is called with enable set to false.
NOTE Use window_mouse_get_locked to get the locked state of the mouse.
window_mouse_set_locked(enable);
Argument | Type | Description |
---|---|---|
enable | Boolean | Whether to lock the mouse or not |
N/A
Step Event
if (window_mouse_get_locked())
{
x += window_mouse_get_delta_x();
y += window_mouse_get_delta_y();
}
Global Left Pressed Event
window_mouse_set_locked(true);
Global Left Released Event
window_mouse_set_locked(false);
The above code adds the change in mouse position to the instance's position while the left mouse button is held down.
In the Global Left Pressed and Global Left Released events, the mouse is set to locked and unlocked respectively, using window_mouse_set_locked.
In the Step event, the locked state of the mouse is checked using window_mouse_get_locked. If it is locked, the delta x (window_mouse_get_delta_x) and y (window_mouse_get_delta_y) are added to the instance's x and y.