• getBounds


    /*用法:
    
    目标显示对象.getBounds(参照显示对象)//返回一个矩形显示对象区域A(x,y,width,height),
    
    这个A就是目标显示对象的显示区域;
    
    宽度,高度就没啥好说的了,就是这个A的宽和高;
    
    坐标x,y为参照显示对象在A的左上角的坐标值(属于本地坐标);
    
    如果要获得全局坐标参照显示对象应为root。*/
    
     
    
    var container:Sprite = new Sprite();
    container.x = 150;
    container.y = 150;
    container.graphics.beginFill(0xfff000);
    container.graphics.drawCircle(0,0,50);
    this.addChild(container);
    
    var contents:Shape = new Shape();
    contents.graphics.beginFill(0xff0000);
    contents.graphics.drawCircle(50,50,50);
    container.addChild(contents);
    
    //取得root的矩形显示区域;
    trace(getBounds(root));
    trace(this);
    //(x=100, y=100, w=150, h=150)
    trace(getBounds(container));
    //(x=-50, y=-50, w=150, h=150)
    trace(getBounds(contents));
    //(x=-50, y=-50, w=150, h=150)
    
    //取得container的矩形显示区域
    trace(container.getBounds(root));
    //(x=100, y=100, w=150, h=150)
    trace(container.getBounds(container));
    //(x=-50, y=-50, w=150, h=150)
    trace(container.getBounds(contents));
    //(x=-50, y=-50, w=150, h=150)
    
    //取得contents的矩形显示区域
    trace(contents.getBounds(root));
    //(x=150, y=150, w=100, h=100)
    trace(contents.getBounds(container));
    //(x=0, y=0, w=100, h=100)
    trace(contents.getBounds(contents));
    //(x=0, y=0, w=100, h=100)
    
    
    var container:Sprite = new Sprite();
    container.graphics.beginFill(0xff0000,1);
    container.graphics.drawRect(0,0,200,200);
    container.graphics.endFill();
    container.x = 100;
    container.y = 100;
    this.addChild(container);
    
    var contents:Shape = new Shape();
    contents.graphics.beginFill(0xffff00,1);
    contents.graphics.drawCircle(0,0,100);
    contents.graphics.endFill();
    container.addChild(contents);
    
    
    trace(contents.getBounds(container));
    
    // (x=-100, y=-100, w=200, h=200)
    
    
    trace(contents.getBounds(this));
    
    
    // (x=0, y=0, w=200, h=200)
    
  • 相关阅读:
    CSS的未来:游戏的变革Flexbox
    2013年第8周一JAVA对象序列化及TODO标签等
    大年初七回杭州
    2013年2月20日星期三
    2013年周六加班杂记
    大家初八但杭州收拾准备开始工作
    大家初六去香山
    2013年第8周四又是低效的一天
    2013年第8周二Delphi中Union结构
    2013年第8周日元宵节
  • 原文地址:https://www.cnblogs.com/602147629/p/1927101.html
Copyright © 2020-2023  润新知