zoukankan      html  css  js  c++  java
  • 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)
    
  • 相关阅读:
    利用Clojure统计代码文件数量和代码行数
    Workflow:添加工作流存储功能
    MongoDB:最简单的增删改查(Oops,可能太简单了)
    《WF in 24 Hours》读书笔记
    推荐一个学习python的网站
    Inter系列处理器名称浅析
    [Android1.5]TextView跑马灯效果
    Code::Blocks 的配色方案
    PuTTY + Xming 远程使用 Linux GUI
    Linux下查看文件和文件夹大小
  • 原文地址:https://www.cnblogs.com/602147629/p/1927101.html
Copyright © 2011-2022 走看看