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

Post your completed addons to share with the community

Post » Tue Apr 22, 2014 2:07 am

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: ...er, 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: https://developer.mozilla.org/en-US/doc ... inter_Lock

Specification (Currently, working draft): https://dvcs.w3.org/hg/pointerlock/raw- ... 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.

Cheers,
Tim
Last edited by TiAm on Sat Dec 13, 2014 9:02 pm, edited 7 times in total.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu May 01, 2014 8:31 am

Real useful.
BUT:
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???
B
5
S
2
Posts: 6
Reputation: 437

Post » Sun May 04, 2014 5:51 am

@TON14

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!

Tim

P.S.

v0.2 coming very soon... ;)
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun May 04, 2014 11:52 am

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

Post » Sun May 04, 2014 5:57 pm

@TON14:

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.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun May 04, 2014 6:11 pm

v0.2 now released. :) See original post for download and changelog.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu May 15, 2014 6:52 pm

v0.3 is out. See original post for download and changelog.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu May 15, 2014 7:47 pm

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.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,836

Post » Mon May 19, 2014 1:15 am

@DatapawWolf

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:
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Tue Jun 10, 2014 7:13 am

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:

https://www.dropbox.com/s/dzc5t9d8ysuna ... _fixed.zip

Cheers, T

P.S.

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.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest