p5.js
p5.js copied to clipboard
Mobile Acceleration examples not working.
Example ex00_Acceleration_Ball_Bounce used to work in 2018 but doesn't now. I tried it on 2 phones today. (Android 6.0.1, Android 10). I made a small program just showing the AccelerationX,Y,Z values - always zero. I guess the code hasn't changed so the problem is security on the phone. I've tried giving Chrome all the permissions available - no better. ex03_Shake_Ball_Bounce the same.
This was a great feature, I've seen 20 10-year-olds all shake their phones with this and laugh. Shame it doesn't work now.
function setup() {
createCanvas(displayWidth, displayHeight);
fill(0);}
function draw() {
background(255);
textSize(36);
textAlign(RIGHT);
text(frameCount , 250, 40);
text(accelerationX, 250, 80);
text(accelerationY, 250, 110);
text(accelerationZ, 250, 140);}
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.
Probably related to some permission request API. I haven't got time to look into this but I plan to have a look at this eventually if someone else didn't get to this first.
Please, please, please...
Any solutions? This bug seems to still be valid.
Does anything set an event listener with this any more? https://github.com/processing/p5.js/blob/ad5c51a73080463804caac604a0cf2181c0274c8/src/events/acceleration.js#L632-L638
From a quick search I couldn't see it getting set up, maybe that's why?
Sorry this took sooooo long. The problem is as I originally suspected a permission issue. DeviceOrientationEvent.requestPermission() and/or DeviceMotionEvent.requestPermission() need to be called before we can access the relevant acceleration and rotation values. As a temporary fix for the users, include the above functions in a mouse click event should enable it (it will pop up a permission request for your users), it may give an error on Android devices so it may need to be checked for existence before hand (don't have an Android device to test myself).
On our end the fix is potentially much more complicated unless we can make accelerationX/YZ etc getters, as we register the event listeners on initialisation, so if we add the requests there it will pop up the request regardless of whether the user is using acceleration features or not in iOS.
One thing I think was suggested before (don't remember where exactly) is to create a utility function for general requests in one function, although it might be better to include the note about the request functions required in the documentation directly.