Detect if the cursor has left the screen?

Get help using Construct 2

Post » Wed Jan 28, 2015 7:22 pm

Hey there,

One more of my simple problems : I can't find how to detect when the cursor leaves the game window.

I tried checking the Mouse position according to a layer's Viewports, but it'll work only when the game has black bars on its side because it's rescaled. When the cursor is simply outside the game's area at all (for instance when it's over the elements of the debugger, or the caption of window, etc.), the Mouse coordinates are not detected anymore from what I can see in the debugger.
(.capx file attached)

Help?
You do not have the required permissions to view the files attached to this post.
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Thu Jan 29, 2015 3:16 am

Try creating an invisible small sprite and pin it to the mouse every tick at position mouse.x, mouse.y and then create the condition as :

Sprite > Is OnScreen (x) > Do something ( x being inverted )
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Thu Jan 29, 2015 3:53 am

Same issue. The sprite won't leave the layout since the Mouse's coordinates are no longer detected from the moment the cursor isn't in the game window.
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Thu Jan 29, 2015 6:03 am

I would create a text box on screen and write the X & Y coordinates to the text box Just to see what it reads when the mouse is off screen. it may be 0, 0 and in that case, you may be able to create a condition that says

Mouse compare X = 0
Mouse compare Y = 0 》do something
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Thu Jan 29, 2015 4:49 pm

I use the debugger to see the Mouse coordinates, and they do actually stop changing from the moment the cursor leaves the game window, leaving them to the last recorded values, which are different every time since I don't always move the mouse at the same speed.
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Mon Feb 23, 2015 9:17 pm

Well, it seems that unlike the Mouse object, the Touch object keeps detecting coordinates even when the... well, the "touch" has left the window. This could be a workaround, but it implies that the player will have to be touching/clicking (and not just moving the cursor around).
B
11
S
3
G
3
Posts: 206
Reputation: 2,379


Return to How do I....?

Who is online

Users browsing this forum: adamebastin, plinkie and 9 guests