![](/img/trans.png)
[英]How to display text sequentially using P5.js deviceMoved() function?
[英]deviceShaken() and deviceMoved() not working on p5.js sketch
function deviceMoved(){
moved = true;
bulb.stop();
playing = false;
}
在我的 Sketch.js (p5.js) 上,這個事件不會在手機上觸發,deviceShaken() 也不會。 谷歌瀏覽器版本在 80 左右,我的手機是華為 P20 Lite。 我正在使用 http,但 https 也沒有產生任何結果。 任何人都知道為什么或如何解決這個問題?
解決了! 這是一個相當棘手的問題。 在 Android 和 iOS 中,您都需要啟用 https。 在 iOS 13+ 中,您還需要請求許可(並且需要在用戶交互中完成)。
像這樣的東西:
if (typeof DeviceMotionEvent.requestPermission === 'function' &&
typeof DeviceOrientationEvent.requestPermission === 'function'
) {
// iOS 13+
askButton = createButton('Permission');
askButton.size(windowWidth*6/8, windowHeight/8);
askButton.position(windowWidth/2 - drumButton.width/2, windowHeight/2);
askButton.mousePressed(() => {
DeviceMotionEvent.requestPermission()
.then(response => {
if (response === 'granted') {
window.addEventListener('devicemotion', deviceMotionHandler, true);
}
});
DeviceOrientationEvent.requestPermission()
.then(response => {
if (response === 'granted') {
window.addEventListener('deviceorientation', deviceTurnedHandler, true)
}
})
.catch(console.error)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.