赞
踩
function chromeInit(mod){ var rotate = new Laya.Vector3(0,0,0); var lastPosition = new Laya.Vector2(0,0); var mousedown = false; Laya.stage.on(Laya.Event.MOUSE_DOWN,this, mouseDown); Laya.stage.on(Laya.Event.MOUSE_MOVE,this, mouseMove); Laya.stage.on(Laya.Event.MOUSE_UP,this, mouseUp) Laya.stage.on(Laya.Event.MOUSE_OUT,this, mouseUp); Laya.stage.on(Laya.Event.MOUSE_WHEEL,this,mouseWheel) function mouseDown(){ lastPosition = new Laya.Vector2(Laya.stage.mouseX,Laya.stage.mouseY); mousedown = true; } function mouseMove(){ if (mousedown) { //移动触碰点 let deltaY = Laya.stage.mouseY - lastPosition.y; let deltaX = Laya.stage.mouseX - lastPosition.x; lastPosition.x = Laya.stage.mouseX; lastPosition.y = Laya.stage.mouseY; //根据移动的距离进行旋转 rotate.setValue(0, 1 * deltaX / 2, 0); mod.transform.rotate(rotate,false,false); } } function mouseUp(){ mousedown = false; } function mouseWheel(e){ let currScale = mod.transform.scale; let newScale; if (e.delta > 0) { newScale = currScale.x + 0.1 > 2 ? 2 : (currScale.x + 0.1 < 0.2 ? 0.2 : (currScale.x + 0.1)); } else { newScale = currScale.x - 0.1 > 2 ? 2 : (currScale.x - 0.1 < 0.2 ? 0.2 : (currScale.x - 0.1)); } mod.transform.scale = new Laya.Vector3(newScale,newScale,newScale); } function offRotate(){ Laya.stage.off(Laya.Event.MOUSE_DOWN,this, mouseDown); Laya.stage.off(Laya.Event.MOUSE_MOVE,this, mouseMove); Laya.stage.off(Laya.Event.MOUSE_UP,this, mouseUp) Laya.stage.off(Laya.Event.MOUSE_OUT,this, mouseUp); } return offRotate; } export { chromeInit }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。