Detect if the cursor has left the screen?

0 favourites
  • 6 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 )

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

  • 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

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)