• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Draw precise x and y mouse coordinates (text and values) on screen

Hi all!

Simple issue, but not able to get it to work correctly.

I have a mouse object. I want it to draw the precise x and y coordinates (text and values) on itself. Its correctly drawing a cursor sprite that I've set for it in its object properties, but the text that's supposed to be on the sprite is constantly being offset and shows incorrect values. Here's what I have:

End Step:

GML:
x=mouse_x
y=mouse_y
Draw GUI End:

draw_text(x,y,"X"+string(x))
draw_text(x,y+10,"Y"+string(y))

Please note that the game is scaled up by a factor of 4 from the default resolution. So I tried multiplying the x/y position by 4 as well, but it still gives incorrect values.

Relevant code in controller object:

Code:
global.window_size_native_width=384
global.window_size_native_height=216

global.window_size_windowed_width=1536
global.window_size_windowed_height=864

game_w_start    = global.window_size_windowed_width; //fixed
game_h_start    = global.window_size_windowed_height; //fixed
game_w            = round(global.window_size_windowed_width)
game_h            = round(global.window_size_windowed_height)


display_set_gui_size(game_w_start, game_h_start); //fixed
window_set_size(game_w_start, game_h_start); //fixed

surface_resize(application_surface, game_w, game_h); //port
camera_set_view_size(view_camera[0], game_w, game_h); //view
Room start (I know, compat scripts...):

Code:
__view_set( e__VW.WView, 0, global.window_size_native_width)
__view_set( e__VW.HView, 0, global.window_size_native_height)
__view_set( e__VW.WPort, 0, global.window_size_windowed_width)
__view_set( e__VW.HPort, 0, global.window_size_windowed_height)
Thanks in advance!
 

TheouAegis

Member
What do you mean it's showing incorrect values? It's going to show mouse_x and mouse_y. Those values are never wrong; what is probably wrong is what you perceive those values to be.

You could try moving the coordinate updating to the Begin Draw event. But as far as I recall, mouse coordinates are updated prior to the End Step, not after it.

Or don't read the values of x and y, but rather the values of device_moue_x() and device_mouse_y(), or device_mouse_x_to_gui() and device_mouse_y_to_gui() maybe, since mouse_x and mouse_y are room coordinates, not screen or window coordinates.
 

LunaticEdit

Member
Object x/y is relative to the map and camera. You can't just set it like that. Your best bet is to override the draw event to not draw it (hell I'd just remove the sprite image alltogether), then draw the sprite directly on the draw_gui event.
 
Top