Laya 屏幕聚焦

Laya 屏幕聚焦

@author ixenos 2020-05-13 12:15:08

 

 1         /**
 2          * 屏幕聚焦到指定点位
 3          * @param aimX 地图中的x坐标
 4          * @param aimY 地图中的y坐标
 5          * @param scaleN 缩放倍数
 6          * 
 7          */
 8         public function focusOn(aimX:Number,aimY:Number,scaleN:Number,useTween:Boolean,tweenDuration:Number):void{
 9             Tween.clearAll(_focusBox);
10             
11             //坐标转化
12             var p:Point = _cameraBox.localToGlobal(new Point(aimX,aimY));
13             p = _focusBox.globalToLocal(p);
14             
15             //设定聚焦锚点
16             _focusBox.anchorX = p.x/_focusBox.width;
17             _focusBox.anchorY = p.y/_focusBox.height;
18             
19             //调整偏移量
20 //            _focusBox.x = _focusBox.width*_focusBox.anchorX;
21 //            _focusBox.y = _focusBox.height*_focusBox.anchorY;
22             _focusBox.x = p.x;
23             _focusBox.y = p.y;
24             
25             //聚焦
26             if(useTween){
27                 Tween.to(_focusBox,{scaleX:scaleN,scaleY:scaleN},tweenDuration);
28             }else{
29                 _focusBox.scale(scaleN,scaleN,true);                
30             }
31         }
32         
33         /**
34          * 取消屏幕聚焦
35          * @param useTween
36          * @param tweenDuration
37          * 
38          */
39         public function focusOff(useTween:Boolean,tweenDuration:Number):void{
40             Tween.clearAll(_focusBox);
41             if(useTween){
42                 Tween.to(_focusBox,{scaleX:1,scaleY:1},tweenDuration);                
43             }else{
44                 _focusBox.scale(1,1,true);    
45             }
46         }

 

 
posted @ 2020-05-13 12:16  ixenos  阅读(419)  评论(0编辑  收藏  举报