
                (function() {
                    var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
                    var __module = nodeEnv ? module : {exports:{}};
                    var __filename = 'preview-scripts/assets/Script/tool/Shake.js';
                    var __require = nodeEnv ? function (request) {
                        return cc.require(request);
                    } : function (request) {
                        return __quick_compile_project__.require(request, __filename);
                    };
                    function __define (exports, require, module) {
                        if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '61affD5SO9Ipo0fGmIeTFTZ', 'Shake');
// Script/tool/Shake.js

"use strict";

/**
 * 自定义抖动效果
 */
var Shake = cc.Class({
  "extends": cc.Component,
  properties: {
    //抖动时间
    duration: 0,
    //X轴抖动范围
    shakeX: 0,
    shakeY: 0
  },
  shake: function shake(callback) {
    if (this.shaking) {
      return;
    }

    this.callback = callback;
    this.shaking = true;
    this.dtCost = 0;
    this.nodeInitialPos = this.node.getPosition();
    this.unschedule(this.doSchedule);
    this.schedule(this.doSchedule, 0, cc.macro.REPEAT_FOREVER, 0);
  },
  doSchedule: function doSchedule(dt) {
    var dt2 = dt * 50;
    var randX = this.getRandomStrength(-this.shakeX, this.shakeX) * dt2;
    var randY = this.getRandomStrength(-this.shakeY, this.shakeY) * dt2;
    this.node.setPosition(cc.pAdd(this.nodeInitialPos, cc.v2(randX, randY)));
    this.dtCost += dt;

    if (this.dtCost >= this.duration) {
      this.unschedule(this.doSchedule);
      this.node.setPosition(this.nodeInitialPos);
      this.shaking = false;

      if (this.callback) {
        this.callback();
      }
    }
  },
  //获取两个数间的随机值
  getRandomStrength: function getRandomStrength(min, max) {
    return Math.random() * (max - min + 1) + min;
  }
});

cc._RF.pop();
                    }
                    if (nodeEnv) {
                        __define(__module.exports, __require, __module);
                    }
                    else {
                        __quick_compile_project__.registerModuleFunc(__filename, function () {
                            __define(__module.exports, __require, __module);
                        });
                    }
                })();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4316 characters]