Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

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();
display_mouse_lock(0,0,global.display_width,global.display_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();
display_mouse_lock(global.window_x,global.window_y,global.window_width,global.window_height);
}
#endregion

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

http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/cameras%20a...