Laya 镜头移动缓冲
Laya 镜头移动缓冲
@author ixenos 2020-05-13 12:16:53
1 public function moveUpdate(dt:int):void{ 2 dt = dt * 0.001; 3 var rate:Number = 6; 4 if(_moveToX!=this.x) 5 { 6 if(Math.abs(_moveToX-this.x)>MOVE_X) 7 { 8 var moveX:Number = _moveToX - this.x; 9 moveX = moveX * rate * dt; 10 if(Math.abs(moveX) < MOVE_X) 11 { 12 moveX = moveX > 0 ? MOVE_X : -MOVE_X; 13 } 14 else if(Math.abs(moveX) > Math.abs(_moveToX - this.x)) 15 { 16 moveX = _moveToX - this.x; 17 } 18 this.x = this.x + moveX; 19 } 20 else 21 { 22 this.x = _moveToX; 23 } 24 } 25 if(_moveToY!=this.y) 26 { 27 if(Math.abs(_moveToY-this.y)>MOVE_Y) 28 { 29 var moveY:Number = _moveToY - this.y; 30 moveY = moveY * rate * dt; 31 if(Math.abs(moveY) < MOVE_Y) 32 { 33 moveY = moveY > 0 ? MOVE_Y : -MOVE_Y; 34 } 35 else if(Math.abs(moveY) > Math.abs(_moveToY - this.y)) 36 { 37 moveY = _moveToY - this.y; 38 } 39 this.y = this.y + moveY; 40 } 41 else 42 { 43 this.y = _moveToY; 44 } 45 } 46 }