GameMaker: Studio

GameMaker: Studio

View Stats:
Moving player object with mouse...continued
Hi, Blyxx helped me to set up this code in order to move my player object using the mouse

In create event:

prevMouseX = mouse_x;
xMove = 0;

In step event:

if mouse_x > prevMouseX
{
xMove = 1;
}

else if mouse_x < prevMouseX
{
xMove = -1;
}

x += xMove;

In end step event:

prevMouseX = mouse_x;

However this code will only move the player object as long as the mouse cursor remains within the window/room. If I move the mouse very fast the cursor moves to the end of the screen and then the player object's movement also stops before I intend it to. I have tried resetting the mouse cursor to the middle of the screen at every step but this causes the movement to be irregular. By the way, I want the mouse cursor to be hidden. Any suggestions
< >
Showing 1-6 of 6 comments
Scarabian Oct 5, 2013 @ 4:54am 
In step event

if (mouse_x > room_width-5) { mouse_x = room_width-5; } if (mouse_x < 5){ mouse_x = 5; } if (mouse_y > room_height-5) { mouse_y = room_height-5; } if (mouse_y < 5){ mouse_y = 5; }
Make sure that you have a game exit menu or key because this will stop you clicking on the close window icon.
if you find that the mouse is still moving too far bring the border in by 5 until it suits your game.
Hope this helps
Steve
regardtvisagie Oct 5, 2013 @ 5:42am 
Thanks Steve, apparently you cannot change the mouse_y or mouse_x as it is read only.
Scarabian Oct 5, 2013 @ 6:58am 
Oops my bad revision:
if (window_mouse_get_x()> window_get_width() - 5){ window_mouse_set(window_get_width()-5,y) } if (window_mouse_get_x()< 5){ window_mouse_set(5,y) } if (window_mouse_get_y()>window_get_height() - 5){ window_mouse_set(x,window_get_height()-5) } if (window_mouse_get_y()< 5){ window_mouse_set(x,5) }
Stupid thing is I used this in a project of my own last week guess I need to sort my brain out, this is screen based but it shouldnt be a problem with your game (I think). If its the body hack n slash you are still using it for.
regardtvisagie Oct 6, 2013 @ 12:23am 
In theory your suggestion also makes sense but for some reason the object just shudders when the mouse cursor hits the edge of the screen...
Scarabian Oct 6, 2013 @ 11:24am 
Is your code based around the acceleration of the mouse cursor?
regardtvisagie Oct 6, 2013 @ 11:41am 
The speed at which you physically move the mouse doesn't have an effect on the speed of the object's movement nor does the speed of the cursor. The code just checks whether the mouse cursor changes position, irrespective of how far. If the mouse position changes the object position also changes by a set distance (the code above says 1 pixel but it is now 5). The movement of the object is therefore relatively slow. In other words, if you want to move the object far you also have to move the mouse relatively slow so that the cursor doesn't reach the edge of the screen too quickly. Moving the mouse this slow doesn't come naturally and is thus frustrating. Having low mouse sensitivity will work so that even though you physically moving the mouse quickly the cursor on the screen still moves slowly and thus the object can also move further. However, as I understand it, it is not possible to change the mouse sensitivity in gml.
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Oct 5, 2013 @ 1:56am
Posts: 6