GMS 2 prevent mouse outside GUI area

P

PandaPenguin

Guest
Im not sure if it's just me doing it plain wrong or if there is just no simple way for this problem:

example:
you have a 16:9 game and want it to run in fullscreen
works fine on all 16:9 displays but has black bars on any other aspecr ratio display (when you want to keep aspect ratio and not distort your graphics)

problem:
these black bars count as game area too so any stuff that happens on GUI layer gets involved
anything drawn on GUI layer can be drawn there unintentionally, like a sprite that follows the mouse (custom cursor, crosshairs etc)
clicks that happen on black bars get detected too

solution 1:
use clamp() to limit any mouse_x/y coordinate uses to the GUI area only (with conversion from world coordinates to gui coordinates first)
use same GUI area limitation for all mouse clicks to ensure they happened "inside" the actual game area

solution 2,3,4,5,6?:
dynamically resize application area, gui layer, camera port to adapt to the different aspect ratios?
how would you manage the dynamic scaling so that you dont accidentally "see" more of the world on different ratios than intended?
keep the height and only adjust the width to fit the displays aspect ratio?

I added some shots to maybe better visualize what I mean by "outside GUI area"

default, non fullscreen 1024x768 game window


fullscreen 1024x768 game on a 1920x1080 display, keeping aspect ratio, mouse "outside"


I dont mind the black borders on different aspect ratios, all I'd need is a good solution to prevent the mouse from acting on them, dont know if there is something built in for that (other than what I already do in solution 1)....

and sorry if thats maybe an already good documented question, I somehow couldn't find a solution by now :D
 
Top