How do I constrain mouse cursor within layout / window

Get help using Construct 2

Post » Thu May 28, 2015 6:53 pm

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!
B
6
S
2
Posts: 14
Reputation: 528

Post » Thu May 28, 2015 7:26 pm

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu May 28, 2015 9:08 pm

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 :) (I am on 200, yours is on 206 I think it said) :) So I will update C2 and do all that tomorrow, it is too late for me now.

Thank you again!
B
6
S
2
Posts: 14
Reputation: 528

Post » Thu May 28, 2015 9:43 pm

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) :)
B
6
S
2
Posts: 14
Reputation: 528

Post » Thu May 28, 2015 10:11 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jun 10, 2015 8:12 pm

Hi,
just stopping by to say thank you! Your solution fixed what I was trying to achieve!
B
6
S
2
Posts: 14
Reputation: 528


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Google [Bot] and 11 guests