Page 1 of 4

[Plugin] Mouse Lock (v0.5)(UPDATED)

PostPosted: Tue Apr 22, 2014 2:07 am
by TiAm
Note: v0.3 does not minify correctly. v0.5, despite the version increase, merely fixes this minify glitch. Grab 0.3 for test capx and documentation. Will update the rest of the page when I roll in some real changes (response curves). Link to 0.5 plugin below:

Download Mouse Lock v0.5 (Plugin Only)

Version 0.3:

v0.3 Changelog

Download Mouse Lock v0.3

Mouse Lock:

This my first -- :D -- c2 plugin, Mouse Lock v0.3:

This plugin lets you lock the cursor. That's about it. However, I'm making an attempt to complicate this plugin beyond all reason. :shock:

Some info:

It works in Firefox and Chrome. Other browsers are NOT supported.

When activated, your normal cursor disappears. Press ESC to get it back.

When cursor is locked, the normal mouse plugin x/y readouts won't work :( . However, clicks and mouse wheelies still work. So, you may want to use this with the mouse/touch plugin(s), as opposed to by itself.

Released under Creative Commons Attribution 4.0 International license. Basically, do what you want with the plugin, but if you do modify it, just make it clear it's a fork, and not one of my versions. ;)

What's working (I hope):

1. Pointer lock should work for firefox and chrome. Again: will not work in any other browsers.

2. Can get Raw values(X/Y) which indicate movement change per tick. No settings affect raw except for 'Disable if Unlocked', which disables getting raw x/y or MouseLock x/y readout (you can still see them under debug, but their expressions return an impossible value).

3. Can get MouseLock values(X/Y). For now, this bounds the cursor to the current window size. This value is also affected by Cursor Speed, Deadzone, Speed Cap, and Invert(X/Y).

4. Can enable/disable pointer lock programatically... :ugeek:, in other words, you can lock/unlock with events (the SetMouseLock action). HOWEVER, the initial lock request must be activated by a button or click (for now, your options are a single or double click; custom key isn't implemented yet). Once that's done, you can use events to lock/unlock to your hearts content.

5. Bounding now works. Can bound to window, layout, or be unbounded. See changelog for details.

What's not done:

1. Smoothing will eventually add an option to smooth the cursor (for example, if you are moving the cursor fast and suddenly stop, it would take a few tick to slow down).

2. Response Curve. This will allow linear or curved. In other words:

if your response curve is 1.0, your curve is linear(no difference.)

if you have a negative curve (< 1.0), your sensitivity will be less when moving your cursor slowly (lets you make fine adjustments).

if positive, your sensitivity (> 1.0) slows as you move it faster (let you move your mouse rapidly with small movements, without larger movements hitting speed cap or moving too far)

More Info on Pointer Lock API:

API Info on MDN: ... inter_Lock

Specification (Currently, working draft): ... index.html

Plugin Download:

Contains plugin, readme, and test capx (r168 or later).

Download Mouse Lock v0.5 (Plugin Only)

Mouse Lock v0.3(FIXED)

Final Words:

Hope this is useful for someone. I made it for my WIP space shooter, because I kept clicking outside of the screen during gameplay. :oops: Suggestions are welcome.


Re: [Plugin] Mouse Lock (v0.1)

PostPosted: Thu May 01, 2014 8:31 am
by TON14
Real useful.
1. How to turn off "release cursor" on ESC in browsers.

2.DONT WORK "release cursor" on ESC in Node-Webkit.
3. DONT WORK "On object Clicked" and "Object touched"
3a. DONT WORK Drag and Drop plugin.

:!: BUG :?: :!: Mouse Lock Bounding=Any always work like Bound to Windows????
Mouse Lock Bounding=Any
HeroSprite behaviors= Scrol To, 8 Directions
Windows Size 100,100
Layout Size 300,300
RUN layout
Move HeroSprite to position 150,150( or Any postion, but not on the window size) in this case MouseLockSprite bounded by started Windows Size 100,100(origin Top-Left). And MouseLockSprite will never be over 100,100 area.
How about to bound cursor by current windows area???

Re: [Plugin] Mouse Lock (v0.1)

PostPosted: Sun May 04, 2014 5:51 am
by TiAm

1. Cannot disable ESC as exit in browsers. This is a safety feature built into the API itself. Don't use ESC for other things in-game.

2. Sloppy testing on my part. Apparently, node-webkit doesn't use ESC to exit. I'll manually add this functionality for v0.2. Thanks for the heads up!

3. On Object Clicked and Object Touched are functions of the mouse and touch plugins respectively. They won't work because they are looking for the position of the mouse cursor, which is hidden and locked to the center of the screen.

To accomplish 'On Object Clicked', use a combination of 'On Click(Left,Right,Any)' and 'Is PointerSprite overlapping Foobar'. On object touched is a little trickier, as this plugin is not really intended for a touchscreen interface.

3a. I'm sorry, but I don't know anything about this plugin. However, it probably doesn't work for the same reason as On Object Clicked and On Object Touched; these conditions use the position of the mouse cursor, not the raw mouse movement. However, I'm sure a drag and drop functionality could be achieved with events.


Finally, on bounding: Yes, right now the only option is bound to window. There will be more options come V0.3. However, there's an easy fix for your problem: instead of setting your pointer sprite to MouselockX/Y, set it to the following:

Set X: CanvasToLayerX(SpriteLayer, MouseLock.MouseLockX, MouseLock.MouseLockY)

Set Y: CanvasToLayerY(SpriteLayer, MouseLock.MouseLockX, MouseLock.MouseLockY)

Hope that helps!



v0.2 coming very soon... ;)

Re: [Plugin] Mouse Lock (v0.1)

PostPosted: Sun May 04, 2014 11:52 am
by TON14
TiAm wrote:@TON14
instead of setting your pointer sprite to MouselockX/Y, set it to the following:

Set X: CanvasToLayerX(SpriteLayer, MouseLock.MouseLockX, MouseLock.MouseLockY)
Set Y: CanvasToLayerY(SpriteLayer, MouseLock.MouseLockX, MouseLock.MouseLockY)

It's helped :D
Just Note:
while screen scrolled , pointer sprite move with hero sprite ( pointer sprite keep distance with hero sprite).
It's not bad or good. But somebody will want turn off it or turn on it( for every time ,not just when screen scrolled)

Re: [Plugin] Mouse Lock (v0.1)

PostPosted: Sun May 04, 2014 5:57 pm
by TiAm

Glad that works for you. The pointer should move with the sprite the way I suggested; I think most people would prefer that kind of functionality. However, I have what you are talking about -- scrolling affects pointer position -- on the todo already, as part of the bounding options.

Re: [Plugin] Mouse Lock (v0.2)(UPDATED)

PostPosted: Sun May 04, 2014 6:11 pm
by TiAm
v0.2 now released. :) See original post for download and changelog.

Re: [Plugin] Mouse Lock (v0.3)(UPDATED)

PostPosted: Thu May 15, 2014 6:52 pm
by TiAm
v0.3 is out. See original post for download and changelog.

Re: [Plugin] Mouse Lock (v0.3)(UPDATED)

PostPosted: Thu May 15, 2014 7:47 pm
by DatapawWolf
I'm surprised at the lack of attention this has. I've seen multiple requests to lock the cursor, before. :p

Either way, thanks! I don't have a use for it now, but may, sometime in the future.

Re: [Plugin] Mouse Lock (v0.3)(UPDATED)

PostPosted: Mon May 19, 2014 1:15 am
by TiAm

Hope you find it useful at some point. 8-)

Working on 0.4, though it's still a few days away at least...trying to refocus on my actual game too. :mrgreen:

Re: [Plugin] Mouse Lock (v0.3)(UPDATED)

PostPosted: Tue Jun 10, 2014 7:13 am
by TiAm
Originally, I uploaded the wrong file for v0.3. I just upped a fixed version. The new filename has '_fixed' appended to it. Please switch; a bunch of the properties are mismatched in the old version. Link is in initial post, and also below: ...

Cheers, T


0.4 is kind of on hold...smoothing, upon more investigation, seems quite silly until browsers can provide higher resolution mouse data; response curves are still planned, but I haven't found an approach I like yet.