Window Bound Mouse

For questions about using Classic.

Post » Thu Sep 22, 2011 4:43 am

Hey guys, is there a way to limit mouse movement to be locked within the boundary of the window?

For instance, I'm using drag and drop on a sprite; if I drag the sprite out of the window and let go of the mouse button, it doesn't recognize that I've let go of the button, which in turn makes the drop event not trigger properly even when the sprite is brought back in. I'd like to avoid all that by just not allowing the mouse to go out of the window. Doable?signumcrucis2011-09-22 04:46:27
B
1
G
1
Posts: 4
Reputation: 433

Post » Thu Sep 22, 2011 12:26 pm

Yes, by replacing the system cursor with a sprite (set the sprite's hotspot to the upper left corner just like a windows mouse cursor). The MouseKeyboard object has an action called "Set cursor visible", which you set to invisible. Also add one event:

+ System: Always (every tick)
-> mouseSprite: Set position to Clamp(MouseX, 0, DisplayWidth), Clamp(MouseY, 0, DisplayHeight)

EDIT: You may also make the range smaller, if it suits your needs. Just change the values for X and Y, eg. Clamp(MouseX, 20, DisplayWidth - 20), Clamp(MouseY, 2, DisplayHeight - 16)tulamide2011-09-22 12:30:00
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Sep 22, 2011 7:12 pm

Oh SWEET! I'll try that out right now. Thanks for that.

On a similar topic, is there a way then to make the clamp a non-rectangle sprite too? I'd like to limit the drag area to within certain paths, so something like "while dragging clamp to sprite area" or some such.
B
1
G
1
Posts: 4
Reputation: 433

Post » Thu Sep 22, 2011 7:33 pm

Oh boo. Same problem still, the sprite cursor stays within the clamp, but the actual mouse cursor doesn't so problems remain with drag and drop weirdness.

(I also applied clamps to the draggable objects, but to no avail.)

Still, thanks for that clamp feature, that's really handy. I suppose I'll just have to make it fullscreen only, though I'd really rather not resort to that.signumcrucis2011-09-22 19:34:09
B
1
G
1
Posts: 4
Reputation: 433

Post » Thu Sep 22, 2011 10:57 pm

The mouse has a higher priority than an application, so it's possible to move off the window and click before the mouse can be clamped. A solution is to force the mouse to the center of the window and just move a sprite when the mouse moves. That is only needed when dragging, otherwise the mouse should be free to move as normal. I also implemented drag n drop with events since the behavior uses the actual mouse position.

http://dl.dropbox.com/u/5426011/examples6/Custom%20drag%20drop.cap
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Sep 22, 2011 11:53 pm

Holy heck! +1000 internets good sir. That's really awesome, thank you for taking the time to do that up. Awesome I say!
B
1
G
1
Posts: 4
Reputation: 433

Post » Thu Jul 11, 2013 6:43 am

Hi R0J0hound, I am not able to open the cap file that you posted. Could you please send the link again.

Basically I am also looking for some functionality where I lock the user mouse movement to only a smaller size within the game window while using drag drop and I need help with that.

Thanks,
Ravindra
For game development / IT services contact - ravindra@actualconcepts.com

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
69
S
18
G
3
Posts: 332
Reputation: 6,783

Post » Sun Dec 06, 2015 10:57 pm

That is quite good, I wonder how it works with a scrolling game:

Position cursor X: Clamp(.x+mousex-scrollx,ScrollXLeft, ScrollXRight)
Position cursor Y: Clamp(.y+mousey-scrolly,ScrollYTopt, ScrollYBottom)

????
I´ve tried that, but you have to keep moving the mouse while scrolling
B
5
S
1
Posts: 28
Reputation: 433


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests