• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

[Solved] Mouse Position incorrect after resolution scaling.



I have had this issue before with previous projects and it is something to do with how I am scaling my game to full screen.

The code for how I scale my game is given below:


MonitorW = display_get_width();
MonitorH = display_get_height();

GameW = 960;
GameH = 540;

Mult = floor(MonitorW / GameW);

global.XOffset = (MonitorW - (GameW * Mult)) / 2;
global.YOffset = (MonitorH - (GameH * Mult)) / 2;

var Set = true;
var Room = room_next(room);
while (Set)
    room_set_view(Room, 0, true, 0, 0, GameW, GameH, 0, 0, GameW, GameH, 0, 0, -1, -1, -1);
    room_set_view_enabled(Room, true);
    if (Room == room_last)
        Set = false;
        Room = room_next(Room);

surface_resize(application_surface, GameW * Mult, GameH * Mult);
display_set_gui_size(MonitorW, MonitorH);
global.GuiHeight = display_get_gui_height();
global.GuiWidth = display_get_gui_width();
I then draw the application surface in a post draw event:
draw_surface_ext(application_surface, global.XOffset, global.YOffset, 1, 1, 0, c_white, 1);
The problem that happens is that the mouse_x coordinate is set at 0 at the left side of the screen and the mouse_x coordinate is set at 960 at the far right of the screen. I want it to be 0 on the left of application surface and 960 on the right of the application surface. Same for the y coordinates.