Log In  

This template enables mouse pointer locking thanks to the JavaScript Pointer Lock API & Pico-8's GPIO system. The mouse pointer will get locked inside the pico-8 frame, while still providing movement deltas from your mouse. Now you can do a proper Marble Madness or Quake remake!

here's a demo cart (also included in the zip below):

Cart #fotubigibu-0 | 2020-05-05 | Code ▽ | Embed ▽ | No License
11

Of course it doesn't work as advertised here on the bbs, nor within the pico-8 binary. You'll get stuck when the pointer quits the frame.

  1. unzip ubmlock.zip in your template dir:
    Windows: C:/Users/{Yourname}/AppData/Roaming/pico-8/plates
    OSX: /Users/{Yourname}/Library/Application Support/pico-8/plates
    Linux: ~/.lexaloffle/pico-8/plates

  2. load the cart in pico (fotubigibu until I figure out how to change its name. I kinda like it though):
    load #fotubigibu-0
  3. export as html, using the above template:
    export mlockdemo.html -p ubmlock
  4. have a taste of freedom!

The mouse handling code is in the first tab:

mouse.lockable : true when the cart is run from the proper html template, false otherwise
mouse.locked : true when the mouse is actually locked within the web browser, false otherwise
(for instance you might want to pause and print a message for the user to click back)
mouse.dx, mouse.dy : mouse deltas!
mouse.x, mouse.y : mouse coordinates, still updated and available for your menus even when the mouse is locked

note that you'll need to call mouse:update() every frame to... update the stuff above!
also the mouse buttons and wheel are not handled here, but still available through the usual stat()

when not lockable there's a fallback to standard mouse input while still trying to provide deltas, for dev purpose, with the result you can see above.

Free to use and modify, no attribution required, have fun!

P#75853 2020-05-05 17:21 ( Edited 2020-09-10 08:44)

Good timing :]

P#75869 2020-05-05 18:17

hey ultrabrite, this is exactly what i've been looking for, sorry if im being blind and wasting your time, but where is the zip file that you said you supplied, i would really love to get this to work to its full potential

edit: found the zip file lol

P#81634 2020-09-10 03:25 ( Edited 2020-09-10 06:24)

when i go thru with your steps i get a message saying plate not found when exporting, is this meant to happen?

P#81642 2020-09-10 06:03

@OriWithCookies:
yep, for some reason the zip link wasn't underscored...
most likely you put the template in the wrong dir? I've updated the original post with better info.
(if you changed your home directory you'll need to put it there)

lol I just noticed the demo has the yaw angle reversed ¯\(ツ)/¯ will fix that later on...

P#81644 2020-09-10 08:42 ( Edited 2020-09-10 08:43)

thank you so much, this helps a ton with my little projects

P#81710 2020-09-11 14:25

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:32:25 | 0.023s | Q:22