laya 下以光标为中心缩放对象
Posted yaolin1228
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laya 下以光标为中心缩放对象相关的知识,希望对你有一定的参考价值。
private MouseWheel(e: Laya.Event) { console.log("event"); let currentSp = e.target as Laya.Sprite; let parentSp = currentSp.parent as Laya.Sprite; console.log("before scale"); console.log(parentSp.mouseX, parentSp.mouseY); this.Zoom(currentSp, parentSp.mouseX, parentSp.mouseY, e.delta); } private Zoom(sp: Laya.Sprite, x: number, y: number, delta: number) { let oldScale = sp.scaleX; let scale = delta > 0 ? 1.1:1/1.1; let newScale = sp.scaleX * scale; // newScale = newScale < 0.1 ? 0.1 : (newScale > 5 ? 5 : newScale); // 获取在缩放比例下,光标相对偏移位置 sp.x = sp.x - (x - sp.x) * (newScale - oldScale) / oldScale; sp.y = sp.y - (y - sp.y) * (newScale - oldScale) / oldScale; sp.scale(newScale, newScale); } }
以上是关于laya 下以光标为中心缩放对象的主要内容,如果未能解决你的问题,请参考以下文章