重力感应本地开发无监听?

  • Creator 版本:“3.6.2”

  • 目标平台: chrome 浏览器 mac

start() {
// this.accelerometerEnable = false;
input.setAccelerometerEnabled(true);
input.setAccelerometerInterval(0.5);
input.on(Input.EventType.DEVICEMOTION, this.moveBall, this);
}

onDestroy() {
    input.off(Input.EventType.DEVICEMOTION, this.moveBall, this);
    input.setAccelerometerEnabled(false);
}

update(dt: number) {
    // log(this.acc.x, 'acc', dt, this.node);
    let pos = this.node.position;
    // this.node.setPosition()
    // let pos = this.target.position;
    this.node.setPosition(pos.x + this.acc.x * dt * this.speed, pos.y);
    pos = this.node.position;
    this.node.setPosition(pos.x, pos.y, pos.z + (-this.acc.y) * dt * this.speed);
}

moveBall(event: EventAcceleration) {
    // on some platforms, stopping accelerometer is an asynchronous operation.
    // need to skip this callback after stopping.
    // if (this._skipCallback) {
    //     return;
    // }
    log(event.acc.x, 'event');
    this.acc.x = event.acc.x;
    this.acc.y = event.acc.y;
}

监听无响应

检查一下position的设置

上 https 环境吧

moveBall
这个函数都没有进入

上了 但是没效果 moveBall 函数都没进

浏览器也支持重力感应吗

deviceorientation