LayaBox---背景拖动
Posted 格拉格拉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LayaBox---背景拖动相关的知识,希望对你有一定的参考价值。
刚接触laya 还不知道有没有更方便好用的拖动场景方法,就整了个 如下脚本,来实现大场景拖动。
将脚本挂载到要拖动到场景父物体上即可
export default class SceneMove extends Laya.Script
constructor() super();
private mouseX = 0;
private minX = 0;
private moveLeft = false;
private moveRight = false;
private canMove = false;
//X移动范围
private leftX = -300;
private rightX = 1380;
onMouseDown()
this.minX = Laya.MouseManager.instance.mouseX;
onMouseUp()
this.setMoveState();
onMouseMove()
this.canMove = true;
onUpdate()
if(this.canMove==false) return;
this.mouseX = Laya.MouseManager.instance.mouseX;
if(this.mouseX>this.minX)
if((this.owner as Laya.Panel).x<this.rightX)
this.moveLeft = true;
else
if((this.owner as Laya.Panel).x>this.leftX)
this.moveRight = true;
if(this.moveLeft)
(this.owner as Laya.Panel).x += 10;
if((this.owner as Laya.Panel).x>=this.rightX)
this.setMoveState();
if(this.moveRight)
(this.owner as Laya.Panel).x -= 10;
if((this.owner as Laya.Panel).x<=this.leftX)
this.setMoveState();
setMoveState()
this.canMove = false;
this.moveLeft = false;
this.moveRight = false;
以上是关于LayaBox---背景拖动的主要内容,如果未能解决你的问题,请参考以下文章