说明 :

下面监听中的 acc属性 里面有很多可以使用的值 .

添加监听 :

cc.inputManager.setAccelerometerEnabled(true);
cc.eventManager.addListener({
    event: cc.EventListener.ACCELERATION,
    callback: function(acc, event){
        var fource = 4;
        if(Math.abs(acc.x) >= fource || Math.abs(acc.y) >= fource)
        {
            cc.log("检测剧烈摇晃手机");
        }
    }.bind(this)}, this);

 

删除当前层时 , 移除监听 :

onExit: function () {
    this._super();
    cc.eventManager.removeListener(cc.EventListener.ACCELERATION);
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案