HTML5 PLEASE!! I need help with wrong mouse coordinates for today

R

rbfraphael

Guest
Good afternoon!

I'm creating a little game with GameMaker-Studio for my work and I have some problems with mouse coordinates when game canvas is scaled.



Here is the function I'm using to rescale window:

Code:
// argument0 = base_width (room_width)
// argument1 = base_height (room_height)
// argument2 = width (browser_width)
// argument3 = height (browser_height)

aspect = argument0 / argument1;

if(argument2 / aspect > argument3){
    width = argument3 * aspect;
    height = argument3;
} else {
    width = argument2;
    height = argument2 / aspect;
}

window_set_size(width, height);
surface_resize(application_surface, width, height);
It's so important because I need to delivery this game today :( PLEASE can someone help me??
 
R

rbfraphael

Guest
To follow the mouse, I'm just using

Code:
x = mouse_x;
y = mouse_y;
 

CloseRange

Member
Not sure if this will work, there isn't really much time to figure out the soul solution so I'll offer a quick fix.
Use the ration of the mouse and compare it to the ratio of the object. Replace you current follow mouse code (x = mouse_x; y = mouse_y;) with something like this:
Code:
var w = display_get_width(); // width (display)
var h = display_get_height(); // height (display)
var mx = display_mouse_get_x(); // Mouse x (display)
var my = display_mouse_get_y(); // Mouse y (display)

var px = mx / w; // percet of x value
var py = my / h; // percent of y value

x = room_width *px; // Go to the percent place of the room
y = room_height *py; // Go to the percet place of the room
If you notice any errors please let me know

Hope this helped! :mad:
-CloseRange
 
Top