核心显示类:

描述
DisplayObject 显示对象基类,所有显示对象均继承自此类
Bitmap 位图,用来显示图片
Shape 用来显示矢量图,可以使用其中的方法绘制矢量图形
TextField 文本类
BitmapText 位图文本类
DisplayObjectContainer 显示对象容器接口,所有显示对象容器均实现此接口
Sprite:DisplayObjectContainer 带有矢量绘制功能的显示容器
Stage:DisplayObjectContainer 舞台类

根节点:  

  Egret 的教程说 “每个Egret应用有且只有一个stage对象”,直接看 Egret 的 Player 播放器代码:

            p.init = function (container, options) {
var option = this.readOption(container, options);
var stage = new egret.Stage();
stage.$screen = this;
stage.$scaleMode = option.scaleMode;
stage.$orientation = option.orientation;
stage.$maxTouches = option.maxTouches;
stage.frameRate = option.frameRate;
stage.textureScaleFactor = option.textureScaleFactor;
var buffer = new egret.sys.RenderBuffer(undefined, undefined, true);
var canvas = buffer.surface;
this.attachCanvas(container, canvas);
var webTouch = new web.WebTouchHandler(stage, canvas);
var player = new egret.sys.Player(buffer, stage, option.entryClassName);
var webHide = new egret.web.WebHideHandler(stage);
var webInput = new web.HTMLInput();
player.showPaintRect(option.showPaintRect);
if (option.showFPS || option.showLog) {
player.displayFPS(option.showFPS, option.showLog, option.logFilter, option.fpsStyles);
}
this.playerOption = option;
this.container = container;
this.canvas = canvas;
this.stage = stage;
this.player = player;
this.webTouchHandler = webTouch;
this.webInput = webInput;
this.webHide = webHide;
egret.web.$cacheTextAdapter(webInput, stage, container, canvas);
this.updateScreenSize();
this.updateMaxTouches();
player.start();
            p.initialize = function () {
var rootClass;
if (this.entryClassName) {
rootClass = egret.getDefinitionByName(this.entryClassName);
}
if (rootClass) {
var rootContainer = new rootClass();
this.root = rootContainer;
if (rootContainer instanceof egret.DisplayObject) {
this.stage.addChild(rootContainer);
}
else {
DEBUG && egret.$error(1002, this.entryClassName);
}
}
else {
DEBUG && egret.$error(1001, this.entryClassName);
}

  可以清楚地看到,egret 将 Main 这个 DisplayObjectContainer 作为了播放器的 rootContainer,并在初始化时就为 Main.stage 创建了舞台对象。

显示对象的基本概念:

  • 坐标:x, y
  • 缩放比例:scaleX, scaleY
  • 透明通道:alpha
  • 旋转操作:rotation
  • 设置锚点:anchorOffsetX, anchorOffsetY
  • 斜切:skewX, skewY

显示容器:

  可以包含多个 DisplayObject。

    private createGameScene():void
{
console.log(this.stage.stageWidth);
console.log(this.stage.stageHeight); console.log("Runtime start."); var testCGrid = new MyGrid();
testCGrid.drawGrid();
this.addChild(testCGrid); var testContainer = new MyContainer();
testContainer.drawGrid();
this.addChild(testContainer); console.log("Runtime end.");
}
} class MyGrid extends egret.Shape
{
public constructor()
{
super();
this.drawGrid();
} public drawGrid()
{
this.graphics.beginFill(0x0000ff);
this.graphics.drawRect(0,0,50,50);
this.graphics.endFill();
this.graphics.beginFill(0x0000ff);
this.graphics.drawRect(50,50,50,50);
this.graphics.endFill();
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(50,0,50,50);
this.graphics.endFill();
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0,50,50,50);
this.graphics.endFill();
}
} class MyContainer extends egret.DisplayObjectContainer
{
public constructor()
{
super();
this.drawGrid();
} public drawGrid() {
var myGrid = new egret.Shape();
myGrid.graphics.beginFill(0x00ff00);
myGrid.graphics.drawRect(200,200,50,50);
myGrid.graphics.endFill();
myGrid.graphics.beginFill(0x00ff00);
myGrid.graphics.drawRect(250,250,50,50);
myGrid.graphics.endFill();
myGrid.graphics.beginFill(0xff0000);
myGrid.graphics.drawRect(250,200,50,50);
myGrid.graphics.endFill();
myGrid.graphics.beginFill(0xff0000);
myGrid.graphics.drawRect(200,250,50,50);
myGrid.graphics.endFill();
this.addChild(myGrid); var myRect = new egret.Shape();
myRect.graphics.beginFill(0xc000c0);
myRect.graphics.drawRect(200,0, 100, 50);
myRect.graphics.endFill();
this.addChild(myRect);
}
class MySprite extends egret.Sprite {
public constructor() {
super();
this.drawGrid();
} private drawGrid() {
this.graphics.beginFill(0x00ff00);
this.graphics.drawRect(200,200,50,50);
this.graphics.endFill();
this.graphics.beginFill(0x00ff00);
this.graphics.drawRect(250,250,50,50);
this.graphics.endFill();
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(250,200,50,50);
this.graphics.endFill();
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(200,250,50,50);
this.graphics.endFill(); var myRect = new egret.Shape();
myRect.graphics.beginFill(0xc000c0);
myRect.graphics.drawRect(200,0,100,50);
myRect.graphics.endFill();
this.addChild(myRect);
}
}
  • 第一个是一个自定义对象类;
  • 第二个是一个自定义容器类,包含两个自定义对象类。
  • DisplayContainer 是 Sprite 的话,由于其实现了 graphics 也是可以直接被根容器添加并显示的,它的child也会被显示。

访问容器子对象与深度:

  • getChildByName()
  • getChildAt()

  按官方说法,推荐用显示层级来获取对象效率更高。

  值得注意的是,如果对象是一个容器,容器内又包含多个对象时的层次处理。

Erget 显示对象的更多相关文章

  1. 采用重写tostring方法使ComboBox显示对象属性

    当ComboBox中添加的是对象集合的时候,如果运行就会发现显示是的命令空间.类名,而如果我们想显示对象属性名的时候,我们就可以在对象类中重写object基类中的tostring方法.

  2. Flex4的可视化显示对象

    flex3中用addChild(child:DisplayObject) 增加显示对象,flex4中用addElement(element:IVisualElement).绝大多数的flex3显示控件 ...

  3. Cocos2d-X3.0 刨根问底(五)----- Node类及显示对象列表源码分析

    上一章 我们分析了Cocos2d-x的内存管理,主要解剖了 Ref.PoolManager.AutoreleasePool这三个类,了解了对象是如何自动释放的机制.之前有一个类 Node经常出现在各种 ...

  4. AS3给显示对象加边框

    给显示对象加边框,可以有以下三种方法1.根据相交路径的缠绕规则的奇偶规则法(使用奇偶缠绕规则时,任何相交路径都交替使用开放填充与闭合填充.如果使用同一填充绘制的两个正方形相交,则不会填充相交的区域.通 ...

  5. 用AS3清空容器下所有子显示对象

    容器中的子显示对象分为两类: 处于显示列表中的子显示对象.被numChildren所记录的. 由容器graphics对象绘制出来的矢量图.这个矢量图不属于Shape类型,不在容器的显示列表中,不被nu ...

  6. Unity3D方法来隐藏和显示对象

    Unity3D作 在使用unity3d开发游戏的过程中.我们经常会遇到须要隐藏或者显示的操作,针对这一点,以下做了一些总结. 一.设置Renderer状态 在游戏的开发中,全部可以被渲染的物体都包括有 ...

  7. Egret --视觉编程,显示对象,事件

    1,在egret中,视觉图形都是由显示对象和显示对象容器组成的: 显示对象:准确的说,就是在舞台上显示出来的,包括能真实看见的图形,文字,图片,视频等:也包括不能看见但真实存在的显示对象容器: 一:显 ...

  8. ListBox之类控件的Item项显示对象的两个属性

    wpf项目中,ListBox绑定对象集合,ListBoxItem要显示对象的两个属性,例如:显示员工的工号和姓名. 之前我的做法是在Employee员工类中添加一个"NumAndName&q ...

  9. Xcode在playground的quick look框中显示对象自定义视图

    对于一般对象,playground中默认的quick look显示已经够用,比如简单的字符串,Int,或简单的自定义Class等等. 不过对于有些情况,我们需要自定义对象在playground中的显示 ...

随机推荐

  1. SRM 390(1-250pt)

    DIV1 250pt 题意:给定整数n和k,问最少需要多少个n连接在一起形成的新整数t,使得t是k的倍数.如果不能形成倍数,输出-1.k <= 10^5,n <= 10^9. 解法:不断增 ...

  2. hdu4666 最远曼哈顿距离

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4666 #include <cstdio> #include <cstring> ...

  3. docs

    https://www.eucalyptus.com/docs/eucalyptus/3.4/index.html  [Eucalyptus PDF官方下载] http://aws.amazon.co ...

  4. Android中调用Paint的measureText()方法取得字符串显示的宽度值

    1 public static float GetTextWidth(String text, float Size) { //第一个参数是要计算的字符串,第二个参数是字提大小 2         T ...

  5. JSP写入MySQL数据库中出现乱码问题笔记

    1.在数据库链接字符串上要形如:jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8(注意要加chara ...

  6. geektool--一款很geek的工具

    2016/12/18 今天尝试一款很geek的工具 geektool 听名字就超级geek有木有 get it geektool website 从官网直接下载app,一键傻瓜式安装. use it ...

  7. 基于RMAN的异机数据库克隆(rman duplicate)

    对于基于生产环境下的数据库的版本升级或者测试新的应用程序的性能及其影响,备份恢复等等,我们可以采取从生产环境以克隆的方式将其克隆到本地而不影响生产数据库的正常使用.实现这个功能我们可以借助rman d ...

  8. C#中操作WMI的类库-实现远程登录共享

    WMI是Windows Management Instrumentation的简称,即:视窗管理规范.在Windows 2000或以后的版本中均安装得有,NT4.0则需要安装WMI的核心组件.通过WM ...

  9. "Storage Virtualization" VS "Software-Defined Storage"

    http://www.computerweekly.com/blogs/StorageBuzz/2013/07/storage-virtualisation-vs-soft.html 这篇blog的目 ...

  10. linux网络编程学习笔记之五 -----并发机制与线程�

    进程线程分配方式 简述下常见的进程和线程分配方式:(好吧,我仅仅是举几个样例作为笔记...并发的水太深了,不敢妄谈...) 1.进程线程预分配 简言之,当I/O开销大于计算开销且并发量较大时,为了节省 ...