• 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.

Windows window_mouse_set sometimes does not work

I have it so in my game you can right click and move your mouse to rotate your character
Sometimes, when you click outside the window, and the refocus it, window_mouse_set no longer works until you unfocus and refocus the window.
This is really annoying as sometimes when trying to rotate my character, it will spin out of control because the mouse is not locked in place

I also tried display_mouse_set, but the same thing happens.

Here is my code:
Code:
if mouse_check_button_pressed(mb_right){
            mousex=window_mouse_get_x();
            mousey=window_mouse_get_y();
            window_mouse_set(mousex,mousey);
            window_set_cursor(cr_none)
            chang_x=obj_player_self.direction
    }

if mouse_check_button_released(mb_right){window_set_cursor(cr_default)}

if mouse_check_button(mb_right){
            obj_player_self._rightClick=1
            var px=chang_x;
            chang_x+=(mousex-window_mouse_get_x())/8*-1;
            change_y+=(mousey-window_mouse_get_y())/8;
            change_y=median(-190,change_y,190);
            obj_player_self.direction=floor(chang_x)
            window_mouse_set(mousex,mousey);
       
    }


Is this a bug, or am I doing something wrong?
 
J

jackhigh24

Guest
im not fully understanding this but you could always have a mouse object that has it x and y set to the mouse and have your player thing set to that object, that way when the mouse leaves to window the mouse object stays where you left the window so wont freak out your player thing.
 
im not fully understanding this but you could always have a mouse object that has it x and y set to the mouse and have your player thing set to that object, that way when the mouse leaves to window the mouse object stays where you left the window so wont freak out your player thing.
The mouse leaving the window is not the problem. The problem is that the mouse refuses to lock into place with the function window_mouse_set

Even if the mouse stays in the window, the difference between where the two points (mousex,mousey)-- the initial right click position and (window_mouse_get_x(), window_mouse_get_y())-- the current mouse position becomes so great that the player will rotate out of control
 
C

Chowderchu

Guest
I'm also unclear on your application here, but maybe you could make use of the window_has_focus() function and do something like:

if !window_has_focus()
{
//stop rotating the character or thinking that right click is being held down still
}
 

Lewa

Member
I experienced a similar bug in GMS.
The issue was that sometimes (after starting my project from within GMS) the window_mouse_set() function simply wouldn't work. (I had a first person camera in the game and due to the function not setting the mouse to the middle of the screen in each step, the camera started spazzing out.)

The issue seemed to be focus related. If i clicked the "Run" button in GMs (so that GM started to compile the game) and switched to another window (like Firefox, chrome, File explorer, etc...) then the game would start without focus and this (sometimes) seemed to cause this bug. Only solution was to restart the game and don't change the focus until the game finally started.

This was even reported to YYG (not by me ) http://bugs.yoyogames.com/view.php?id=11602
I don't know if it was fixed or not. I bypassed this bug by writing a DLL which accessed the windows API so that i could directly control the mouse. (worked perfeclty fine).
Of course the issue is that the DLL only works on Windows so multiplatform support goes straight out of the window.
 
Top