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

0 favourites
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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 -- <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> -- 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. <img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked">

    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 <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad"> . 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. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    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... <img src="{SMILIES_PATH}/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek"> ...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. <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed"> Suggestions are welcome.

    Cheers,

    Tim

  • 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.

    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???

  • 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...

  • 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

    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)

  • 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.

  • v0.2 now released. See original post for download and changelog.

  • v0.3 is out. See original post for download and changelog.

  • 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.

  • DatapawWolf

    Hope you find it useful at some point.

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

  • 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.

  • TiAm the mouse lock is not working after I export, It works great in testing but after exporting nothing. Any suggestions?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got to work! You need to uncheck "Minify script" on export. - C2 r172

    This plugin helped a lot, Thank You!

    My Game: 2030 Robot Invasion

    http://www.newgrounds.com/portal/view/640878

  • Knight05

    Thanks for the heads-up; I must have some code in there that isn't minify compliant. I'll try to get that sorted out.

    BTW, left a review/rating on newgrounds.

  • Im having some exportation issues when using this mod(HTML5 and Node Webkit).

    When I run my .exe, or try tu run it on my personal server via web, it crashes, and gets me this error:

    Uncaught node.js Error

    TypeError: undefined is not a function

    at h.$l (file:///C:/Users/******/AppData/Local/Temp/nw8976_6686/c2runtime.js:330:428)

    at HTMLDocument.<anonymous> (file:///C:/Users/****/AppData/Local/Temp/nw8976_6686/c2runtime.js:328:374)

    at HTMLDocument.n.event.dispatch (file:///C:/Users/*****/AppData/Local/Temp/nw8976_6686/jquery-2.1.1.min.js:3:6404)

    at HTMLDocument.r.handle (file:///C:/Users/*****/AppData/Local/Temp/nw8976_6686/jquery-2.1.1.min.js:3:3179)

    I guess the problem is that there are some temporal files associated to this plugins, and they are not created when I launch the game.

    I have also tried to export it without the mouselock plugin, and it works correctly, so It seems the problem is mouselock related.

    Could you tell me why is this happening, or in sort of way, tell me how to resolve it?

    Much Thanks

  • Karapan

    Sorry, but I cannot reproduce on my end.

    What version of C2 are you running? What version of windows? Is this error only on export? Have you tried exporting without minification?

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