码迷,mamicode.com
首页 > 其他好文 > 详细

laya 下以光标为中心缩放对象

时间:2019-01-20 00:59:53      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:get   target   private   OLE   eve   for   tar   mouse   lex   

  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 下以光标为中心缩放对象

标签:get   target   private   OLE   eve   for   tar   mouse   lex   

原文地址:https://www.cnblogs.com/yaolin1228/p/10293753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!