How do I constrain mouse cursor within layout / window

0 favourites
  • 6 posts
From the Asset Store
Mouse cursor is something that the player controls and sees all the time, that's why it is so important to make it cool!
  • Hi,

    It's my first post, am pretty new to Construct 2, so bear with me please

    I have been unable to make mouse cursor "stay" within layout/window. Basically what I am trying to do, I have a layout and window size the same. Let's say it's 1280x1024. When I run the game I made, I want to be able to have mouse cursor not leave that layout.

    Right now it is setup On start of layout - Set cursor to none. I would like it so that when I move my mouse to the outside of my walls (can be seen in the .capx below), that the mouse cursor stays within those walls. As it is now, as soon as the mouse moves outsides, the cursor goes back to the normal arrow cursor, and mouse can be moved all around the screen. I want it to be confined within that layout.

    Something like, if mouse.x(or y) coordinate is less than (or more than) screen x(or y) coordinate - than stay within those coordinates.

    I have included a simpler version of my problem, in this capx :

    https://drive.google.com/folderview?id=0B2knBeHLJj8yfnhael9PWVJHMVZ0OW9JYjJyRzFaaDN2ZjE3OFAyZWFzTW1EbDhlWXJwUE0&usp=sharing

    I hope I asked that understandably.

    Thank so much for any help with this!

  • So how would the mouse get unstuck again if the player would like to go to another program or tab of the browser or..?

    I think this is the best option:

    https://dl.dropboxusercontent.com/u/485 ... clamp.capx

  • Thanks for a reply, I will try your solution tomorrow a bit, and will update this post.

    As for mouse to be unstuck, maybe something like, pressing Escape while "in game", gets mouse back unstuck (and/or pause the game). Something like in VMs (VMware player, Virtualbox...) how there's that combination of keys to grab/release mouse and keyboard input.

    But will definitely try your .capx, I actually tried to open it now, but it says it's made in a newer version So I will update C2 and do all that tomorrow, it is too late for me now.

    Thank you again!

  • Just in case I am going all wrong about this, here is a modified .capx, which actually shows an exact thing that is happening to me. I have added an enemy to the game, which makes a sound everytime it collides with the player.

    But, while mouse cursor is outside the layout/walls, the collision is NOT working (as evident by the lack of explosion sound, which is on collision). So, if mouse moves to any side, and out, then collision is not working. As soon as the mouse moves back in, it is working again. I am trying to make it work that collision works no matter where the mouse cursor is.

    If someone can please tell me how would I fix this, that would be great! I have really tried many things (these .capx-es I am putting here are made this simple on purpose - it's just so I can show what problem I am having).

    modified capx : https://drive.google.com/file/d/0B2knBeHLJj8ya3BkVDRaTkxTc3M/view?pli=1

    Littlestain, in case an answer to my question is in your posted capx file, then I apologize for not checking it first hehe, but I think this is a little different.

    Anyways, thank you and have a good night all! Will update tomorrow (now for real)

  • I can't check your capx, for it has the "bound to layout" third party plugin..

    My capx solution should work, although you might have to adjust some small things to suit your needs..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi,

    just stopping by to say thank you! Your solution fixed what I was trying to achieve!

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