Bound the players mouse cursor to the game window?

  • Hi, i've noticed recently when testing my game that my mouse cursor often flies off screen and when it does, my game no longer registers any mouse input. Is there a way i can lock the mouse to the screen while the game is running in order to prevent this?

    Thanks,Paul.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hmm i was thinking maybe the "Bound to layout" Behaviour? But i can't think of a way of using this on the mouse object. Is this possible?

    Paul

  • Simply put...

    mousex< viewport left...mouse set x to viewport left

    mousex> viewport right...mouse set x to viewport right

    mouse y<viewport top...mouse set y to viewport top

    mouse y > viewport bottom... mouse set Y to viewport bottom...

    You may not need all these...

    this can get more complex depends on your needs and any layers or scrolling you have going on

  • I'm sorry , i don't follow. Is this in the events/actions list? I can only seem to find the options to set the mouse cursor to something else...

    Paul.

  • That are MouseEvents

    If the Mouse leaves the TOP of the game, set the Mouse to the top of the game thats it

    i hope that helps you understand

  • I still can't seem to find any Mouse events that allow me to set the mouse x or y to anything, nor can i find anything about viewport left/right/top or down. I'm fairly new to this, I'm running the unlicensed , free version of construct 2 if that's the reason? I'm fairly new to this and i just can't seem to find any of these things in the event list. Am i clicking Add event>Mouse, and then these events should be there? That's what I've been trying to no avail so far.

    Paul.

  • I have a feeling the answer is going to be very obvious, but i've even tried googling words like mousex and viewport left, in different combinations and the only relevant search results are this thread.

  • Also interested by this and can't find any "set cursor position" action ... Any ideas ?

  • You can't set mouse's position.

    My method is using a sprite as fake cursor (attached below).

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