How do I find out if the mouse moves to the left, right, up

Get help using Construct 2

Post » Tue Oct 28, 2014 9:18 pm

In my game, I need to know if the mouse moves in one of four directions.

But there are no events to test these conditions.

How can I achieve

Thank you in advance

----Traduit du Français---
B
16
S
2
G
1
Posts: 38
Reputation: 1,031

Post » Tue Oct 28, 2014 9:25 pm

You create a variable that stores the position of the mouse pointer, then next tick, or later in your event sheet you compare those values to the current mouse position.

If x is bigger, than you moved right, if Y is bigger you moved down. etc
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Tue Oct 28, 2014 10:28 pm

Ok, thanks a lot !
B
16
S
2
G
1
Posts: 38
Reputation: 1,031

Post » Wed Oct 29, 2014 7:53 pm

@jeromeenligne you might also want to check the distance between the two points so that you arn't checking it moving one pixel

distance( mousestart.x, mousestarty, mouse.x, mouse.y) > 10
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Wed Oct 29, 2014 8:55 pm

Set 5 variables, oldx, newx, oldy, newy and mouse_direction.

Every tick set oldx to newx, and set newx to mouse.x. Do the same for the y values.

Compare 2 values, newx > than oldx set mouse_direction to "right".

newx < than oldx set mouse_direction to "left".


Do the same for the y values.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Sun Nov 02, 2014 9:53 pm

Thank you, I'll watch it. I need to do some tests to see if it matches what I want.

see you soon
B
16
S
2
G
1
Posts: 38
Reputation: 1,031


Return to How do I....?

Who is online

Users browsing this forum: Armench, Jackriduk, kiki4construct, Laurent and 31 guests