[]有震屏的算法吗

已邀请:

laya21126

赞同来自:

/** 是否震动中 */
  protected var _isShake:Boolean;
  /**
   * 震动屏幕 
   * @param callBack
   * @param times
   * @param offset
   * @param speed
   *
   */  
  public function stageShake(callBack:Function = null, times:uint = 2, offset:uint = 12, speed:uint = 32):void
  {
   if(_isShake) return;
   
   _isShake = true;
   var num:int = 0;
   var offsetArr:Array = [0, 0];
   var point:Point = new Point(this.x, this.y);
   Laya.stage.timerLoop(speed, this, shakeObject);
   
   function shakeObject(args:Array=null, frameNum:uint=1, frameTime:uint=0):void{
    var count:int = (num++) % 4;
    offsetArr[num % 2] = count < 2 ? 0 : offset;
    this.x = offsetArr[0] + point.x;
    this.y = offsetArr[1] + point.y;
    if(num > (times * 4 + 1)){
     Laya.stage.clearTimer(this, shakeObject);
     num = 0;
     _isShake = false;
     if(callBack != null)
     {
      callBack();
     }
    }
   }
   
  }
 
直接调用就可以了

Monica - 知识达人

赞同来自:

LayaAir下没有该接口,你可以直接查找js原生的实现方法

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作