说明 :

下面监听中的 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);
}

相关文章: