核心显示类:

描述
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. typedef struct

    突然忘了这玩意儿了..今天就来搞一发 typedef是类型定义的意思.typedef struct 是为了使用这个结构体方便.具体区别在于:若struct node {}这样来定义结构体的话.在申请n ...

  2. Java 判断一段网络资源是否存在

    package cn.ycmedia.common.utils; import java.io.InputStream; import java.net.URL; import java.net.UR ...

  3. 完整的站内搜索Demo(Lucene.Net+盘古分词)

    前言 首先自问自答几个问题,以让各位看官了解写此文的目的 什么是站内搜索?与一般搜索的区别? 很多网站都有搜索功能,很多都是用SQL语句的Like实现的,但是Like无法做到模糊匹配(例如我搜索“.n ...

  4. Android Dialog触摸对话框外部让其消失的实现方法

    方法一: @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent ...

  5. 3DS MAX 导出FBX到Unity3D设置

  6. OpenCV 编码样式指南

    OpenCV 编码样式指南   前言 本文档是对OpenCV中代码风格的简短说明,因为OpenCV的核心库(cv,cvaux)是用C和C++编写的,所以本文档仅对用C和C++代码的编写有效.   文件 ...

  7. [Ruby] Ruby Variable Scope

    Scope defines where in a program a variable is accessible. Ruby has four types of variable scope, lo ...

  8. myeclipse 8.5反编译插件失效

    之前用的好好的,后来加了一个开发工作流的插件,今天打开之后发现反编译插件失效了,后来把开发工作流的插件删掉,又可以了,不知道撒原因,那位大神知道留下点痕迹吧

  9. 开源实时视频码流分析软件:VideoEye

    本文介绍一个自己做的码流分析软件:VideoEye.为什么要起这个名字呢?感觉这个软件的主要功能就是对"视频"进行"分析".而分析是要用眼睛来看的,因此取了&q ...

  10. php include 与 require 起底[转]

    转自 http://www.guangla.com/post/2014-01-24/40060857811 起因: 一朋友面试被问到,php的include和require的区别,这个可能是面试中出现 ...