Jump to content

Problem with mouse detection in browser [Gamemaker 2]


ThatGuyMiniB
 Share

Recommended Posts

I have been having problems when I scale my gamemaker 2 html5 game to fit the height of the browser. Once it scales up it no longer detects the mouse position. Without it being scaled to height I am able to click on my enemies, but when it is scaled to browser height I am unable to. I figure it has to do with the scaling to the browser height :P

Thanks in advance!

 

if(os_type == os_windows){

ideal_width = 0;
ideal_height = browser_height;

start_b_width = browser_width;
start_b_height = browser_height;

aspect_ratio = browser_width/ browser_height;

ideal_width = round(ideal_height / aspect_ratio);

if(ideal_width & 1){
	ideal_width++;
}


room_set_width(rm_game, ideal_width);
room_set_height(rm_game, ideal_height);

surface_resize(application_surface, ideal_width,ideal_height);
room_goto_next();

alarm[0] = 60;
}

//In my alarm

window_set_size(room_width,room_height);

window_center();

 

Link to comment
Share on other sites

Recommend you do some debugging.

Run your engine and draw values to screen and see what they say. E.g. store your mouse_x, mouse_y values to variables on mouse pressed and draw them to screen, plus the various display var you are using. See what's happening.

I suspect on changing your window size you are altering your collision mask locations and so when you click, you are not hitting the masks, but debugging should help you to understand what's happening and then you can work a way to resolve it. 

Link to comment
Share on other sites

I have done some debugging and what I found was that the mouse coordinates are off from the actual mouse.

I made a sprite that would follow mouse_x and mouse_y for my object that registered mouse clicks and it was just way off from the actual mouse, but when the sprite was at the location of and object it can click and destroy it did just that.

I have tried to figure out how to fix this offset but I have had no luck so far.

Link to comment
Share on other sites

Yeah you're offsetting due to your scale engine.  You just need to alter your registered mouse x and y by the same scaling you're applying to your surface/window.

So instead of straight collision checking mouse x mouse y, you'll need to be checking something like mouse x(y) / aspect ratio. Something like that anyway. Without playing with the code I can't quite work it out in my head, but if you use your debug coordinates of what it is reading as x and y and what you expect it to read, you should be able to suss the alteration required.

You can sort of see what I mean in a test engine I made recently here: http://michael-bateman.com/games/B5/

See how the actual mouse x/y are converted to match the alteration due to scaling. This is most obvious on a mobile device. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...