0 Favourites

[UPDATED] Simple Native-like Mouselocking Plugin

  • Simple Mouselock Plugin:

    Download | Simple Mouselock Example: Download

    This plugin makes it possible to make use of native-like pointer locking in your projects and games.

    Compared to the existing but depreciated plugin, this plugin is much more simplified and easier to use.

    The majority of features from the depeciated plugin have been imported, enhanced and optimized.

    Simple mouselocking with several bounding options

    Properties and events to modify the pointer or fetch other useful information

    New properties to auto-enable or activate mouselocking without any events

    Generally simplified & optimized the plugin to improve usability

    Makes it possible to move the mouse pointer infinitly¹. Great for 2D shooters and RTS games!

    Prevents the mouse pointer from going off-canvas, when the game is embedded on a website or in fullscreen².

    Allows the use of a sprite as the mouse pointer, enabling some advanced features (e.g. animated cursors).

    The API uses a type of "software cursor", minor input lag³ can be expected.

    Might require the user to give permissions first.

    IE and older browsers might not support4 this feature.

    ¹ If bounding property is set to "unbounded". ² Usually only affects users with multiple screens. ³ Input lag testing on the web. 4 Chrome status website for support information.

    • Thanks to Armaldio, who updated and made this plugin possible (Donations ? Website)
    • Pointer Lock API MDN Web docs (?)
    • Video introducing the pointer lock API (?)
    • Pointer lock api demo project (?)
    • Depreciated Mouselocking plugin (?)
    • Icon created by Freepik (?)

  • Awesome! This plugin got released just in time for my 2D shooter's weapon wheel. When the weapon wheel UI pops up, I need to get mouse input even if the mouse is at the top limit of the screen. The mouse raw input did the trick. Thanks!

  • Awesome! This plugin got released just in time for my 2D shooter's weapon wheel. When the weapon wheel UI pops up, I need to get mouse input even if the mouse is at the top limit of the screen. The mouse raw input did the trick. Thanks!

    Cool, glad that you also found use for mouse locking in your game!

    It might be worth mentioning here since I forgot to do it in the main post but this plugin doesn't support minifying.

    If anyone is minifying their game on export, it will unfortunately break this plugin at the current state.

  • I came across 2 issues with the plugin that happens even with the example cap.

    The first is that when you go into full screen, the mouse seems to be locked to the previous window size. This can be worked around by disabling the mouselock, then re-enabling it.

    The second issue seems to happen randomly. When I preview your cap file, I click on the viewport to activate the mouse lock. Then if I just move the mouse around for a few seconds, the cursor will jump locations. Any chance you could look into this?

  • I came across 2 issues with the plugin that happens even with the example cap.

    The first is that when you go into full screen, the mouse seems to be locked to the previous window size. This can be worked around by disabling the mouselock, then re-enabling it.

    The second issue seems to happen randomly. When I preview your cap file, I click on the viewport to activate the mouse lock. Then if I just move the mouse around for a few seconds, the cursor will jump locations. Any chance you could look into this?

    I gave it over to Armaldio a couple of days ago, these bugs are quite difficult to fix but it should be possible (hopefully).

    Sorry for the late response. I will keep you posted about the progress.

    • <Fixed> Bounding Area not updating when going into fullscreen

      (*requires workaround, included in the example)

    • <Fixed> Mouse pointer jumping in "bound to window" mode
    • <Fixed> Setting pointer position X/Y not working in fullscreen mode
    • <Other> Updated plugin example to address some minor issues
    • <Other> Performance improvements and code optimization

    Cheers!

  • Okay, i´m a bit confused.

    I tried to set the plugin to "unbound" but the mouse (or at least the sprite that is bound to the mouse coordinates) is bound to the layout.

    Please tell me that i´m just to dumb to use it. ^^

    Here is a video.

    https://youtu.be/9Rdb3sAxbT8

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Okay, i´m a bit confused.

    I tried to set the plugin to "unbound" but the mouse (or at least the sprite that is bound to the mouse coordinates) is bound to the layout.

    Please tell me that i´m just to dumb to use it. ^^

    You're not!

    Here is a video.

    https://youtu.be/9Rdb3sAxbT8

    It looks like the unbounded property is bugged. Probably a result of fixing a previous bug.

    Gave it over to Armaldio, he should be able to fix it as soon as he's got the time to.

    EDIT: Update released, please remove all previous versions before installing the updated plugin!

    • <Fixed> Bounding Area "Unbound" property not working correctly
    • <Other> Updated example project to support the most recent version

    Cheers!

  • Thx, works great now. ^^

  • Is there a plugin for C3 as well?

  • Is there a plugin for C3 as well?

    Asked Armaldio about this and he says that should be doable.

    It might take a couple of days so I'd recommend subscribing to this topic to get notifications about the latest progress.

  • Unfortunately I'm unable to use this plugin since at random intervals it seems to read the raw mouse movement as opposite, and at a much greater speed compared to what I'm actually doing. So say I'm moving a sprite using the raw values to the right and it's reading raw X at around 2 to 9 - suddenly it will jump to the left at a raw x value of something like -280 for no apparent reason. Anyone else experiencing this?

    See these logged raw values as an example:

  • Unfortunately I'm unable to use this plugin since at random intervals it seems to read the raw mouse movement as opposite, and at a much greater speed compared to what I'm actually doing. So say I'm moving a sprite using the raw values to the right and it's reading raw X at around 2 to 9 - suddenly it will jump to the left at a raw x value of something like -280 for no apparent reason. Anyone else experiencing this?

    See these logged raw values as an example: <image>

    I believe this is the fault of the API and not of the actual plugin code. The Mouselock API is known for being buggy like that sometimes.

    Do you have the same problem when using "normal" and not "raw" coordinates?

    (P.s. We're currently having a completely reworked plugin in testing which will add C3 support and might fix issues like that as well.)

  • Ah, sorry, I forgot to mention as well that this was in NW.js.

    I investigated further and found this: https://github.com/nwjs/nw.js/issues/6336#issuecomment-352252411 I've been on a version a few versions back, avoiding to update in case it breaks a big project of mine. Testing v0.29.0 it seems the fix has been implemented, however, everything runs at 30 fps now (was hitting 144 fps without issues before) so I'll have to do some more testing, restart my computer and maybe try v0.28.0 too. I'll update with further findings.

    EDIT:

    So v0.28.0 seems to be the best solution for now if you don't wanna fiddle too much. Mouse lock works and the performance is good.

    I found the reason for the poor performance with v0.29.0 (Ashley and NW.js devs are aware as you can see): https://github.com/nwjs/nw.js/issues/6498

    Hopefully an updated version will be available soon that doesn't require manual handling of those command line arguments.

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