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

AS3 localToGlobal、globalToLocal方法的总结

时间:2017-09-09 10:42:07      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:lan   private   sprite   begin   cal   awr   .com   oba   log   

(1).localToGlobal (point)   把point看成在(1)内部,计算出该point相当于stage的坐标

(2).globalToLocal (point)   point为全局坐标,计算出该point相当于(2)的坐标

 

package
{
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.geom.Point;
        
        
        public class testZuoBiaoZhuanHuan extends Sprite
        {
                private var s1 : Sprite = new Sprite();
                private var s2 : Sprite = new Sprite();
                private var s3 : Sprite = new Sprite();
                
                private var pointTemp : Point = new Point(10,10);
                private var pointResult : Point;

                
                
                public function testZuoBiaoZhuanHuan()
                {
                        this.addEventListener(Event.ADDED_TO_STAGE,onAddToStage);
                }
        
                private function onAddToStage(e : Event):void
                {
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        stage.align = StageAlign.BOTTOM;
                        
                        addChild(s1);
                        s1.graphics.beginFill(0xff0000);
                        s1.graphics.drawRect(0,0,80,80);
                        s1.graphics.endFill();
                        
                        s1.addChild(s2);
                        s2.x = 10;
                        s2.y = 10;
                        s2.graphics.beginFill(0x00ff00);
                        s2.graphics.drawRect(0,0,60,60);
                        s2.graphics.endFill();
                        
                        s2.addChild(s3);
                        s3.x = 10;
                        s3.y = 10;
                        s3.graphics.beginFill(0x0000ff);
                        s3.graphics.drawRect(0,0,40,40);
                        s3.graphics.endFill();
                        
                        pointResult = s1.localToGlobal(new Point(10,10));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s2.localToGlobal(new Point(20,20));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s3.localToGlobal(new Point(30,30));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s1.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s2.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.

                        pointResult = s3.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.y);
                                
                }
                
        }
}


  原文:http://bbs.9ria.com/thread-100884-1-3.html

AS3 localToGlobal、globalToLocal方法的总结

标签:lan   private   sprite   begin   cal   awr   .com   oba   log   

原文地址:http://www.cnblogs.com/dt1991/p/7497291.html

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