• AS3 localToGlobal、globalToLocal方法的总结


    (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

  • 相关阅读:
    MySQL重置密码
    linux下自动备份脚本并上传到ftp服务器
    nginx配置
    WIFI防蹭网
    无线路由知识
    009汇编环境搭建
    008 计算机不会加法
    007计算机不会做加法
    006源码反码补码
    005有符号数和无符号数
  • 原文地址:https://www.cnblogs.com/dt1991/p/7497291.html
Copyright © 2020-2023  润新知