Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

Native mouselock for GameMaker

Constrains the mouse cursor to a rectangle at system level · By YellowAfterlife

Works perfectly on main monitor, but not on second monitor

A topic by Seet created Aug 10, 2020 Views: 275 Replies: 1
Viewing posts 1 to 2

I have a secondary monitor and it is not set to my main display. When I drag my game over to there, it locks my cursor to the main display.

This is the code i'm using:

#region Lock the cursor to gui again
//Fullscreen mode
if (window_get_fullscreen())
fullscreen = true;
global.display_width = display_get_width();
global.display_height = display_get_height();
//Windowed mode
else if (!window_get_fullscreen())
fullscreen = false;
global.window_width = window_get_width();
global.window_height = window_get_height();
global.window_x = window_get_x();
global.window_y = window_get_y();

Developer (1 edit)

You'll want to use window_get_visible_rects with rectangle_in_rectangle/point_in_rectangle to figure out which monitor the game window is on, then use that monitor's coordinates