Erget 显示对象
核心显示类:
| 类 | 描述 |
|---|---|
| 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 显示对象的更多相关文章
- 采用重写tostring方法使ComboBox显示对象属性
当ComboBox中添加的是对象集合的时候,如果运行就会发现显示是的命令空间.类名,而如果我们想显示对象属性名的时候,我们就可以在对象类中重写object基类中的tostring方法.
- Flex4的可视化显示对象
flex3中用addChild(child:DisplayObject) 增加显示对象,flex4中用addElement(element:IVisualElement).绝大多数的flex3显示控件 ...
- Cocos2d-X3.0 刨根问底(五)----- Node类及显示对象列表源码分析
上一章 我们分析了Cocos2d-x的内存管理,主要解剖了 Ref.PoolManager.AutoreleasePool这三个类,了解了对象是如何自动释放的机制.之前有一个类 Node经常出现在各种 ...
- AS3给显示对象加边框
给显示对象加边框,可以有以下三种方法1.根据相交路径的缠绕规则的奇偶规则法(使用奇偶缠绕规则时,任何相交路径都交替使用开放填充与闭合填充.如果使用同一填充绘制的两个正方形相交,则不会填充相交的区域.通 ...
- 用AS3清空容器下所有子显示对象
容器中的子显示对象分为两类: 处于显示列表中的子显示对象.被numChildren所记录的. 由容器graphics对象绘制出来的矢量图.这个矢量图不属于Shape类型,不在容器的显示列表中,不被nu ...
- Unity3D方法来隐藏和显示对象
Unity3D作 在使用unity3d开发游戏的过程中.我们经常会遇到须要隐藏或者显示的操作,针对这一点,以下做了一些总结. 一.设置Renderer状态 在游戏的开发中,全部可以被渲染的物体都包括有 ...
- Egret --视觉编程,显示对象,事件
1,在egret中,视觉图形都是由显示对象和显示对象容器组成的: 显示对象:准确的说,就是在舞台上显示出来的,包括能真实看见的图形,文字,图片,视频等:也包括不能看见但真实存在的显示对象容器: 一:显 ...
- ListBox之类控件的Item项显示对象的两个属性
wpf项目中,ListBox绑定对象集合,ListBoxItem要显示对象的两个属性,例如:显示员工的工号和姓名. 之前我的做法是在Employee员工类中添加一个"NumAndName&q ...
- Xcode在playground的quick look框中显示对象自定义视图
对于一般对象,playground中默认的quick look显示已经够用,比如简单的字符串,Int,或简单的自定义Class等等. 不过对于有些情况,我们需要自定义对象在playground中的显示 ...
随机推荐
- docs
https://www.eucalyptus.com/docs/eucalyptus/3.4/index.html [Eucalyptus PDF官方下载] http://aws.amazon.co ...
- 浅谈异步IO各模型优缺点
本文只讨论OverLapped I/O的三种异步模型及完成端口,像select.SWASelect不作讨论,讨论顺序从劣到优,方便于循序渐进地对比,更容易区分各模型之间的差别. 1. OverLapp ...
- XQuery FLWOR 表达式
FLWOR 是 "For, Let, Where, Order by, Return" 的只取首字母缩写.for 语句把 bookstore 元素下的所有 book 元素提取到名为 ...
- OpenERP里面继承的用法
最近开发遇到了这样的问题:需要往HR模块里面添加一些查询条件,这些查询条件是HR模型里已经写好的,直接修改HR肯定可以实现,但是HR模块一旦修改就会导致一系列的错误,OE开发中的一项基本原则就是不可修 ...
- S3C2440 I2C总线控制
概述:话不多说,直接上图 多主机IIC总线控制(IICCON): IIC控制总线状态(IICSTAT): IIC总线地址(IICADD): IIC发送,接收总线寄存器(IICDS) IIC总线控制寄存 ...
- phpcms如何嵌套循环
PHPCMS V9的标签制作以灵活见长,可以自由DIY出个性的数据调用,对于制作有风格有创意的网站模板很好用,今天就介绍一个标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/php ...
- android studio c++ 自动补全
这两天弄起来了Android ndk,可这东西的配置实在是个问题.对于Eclipse可以通过makefile进行编译,也比较成熟.但是对Android studio来说就蛋疼了,官方是想通过gradl ...
- Swift还是Objective-C
Swift还是Objective-C Swift还是Objective-C? Swift语言发布已经两年了,iOS开发需要学习C或者Objective-C.此外,人们似乎还在迷惑Swift到底适合 ...
- jQuery代码优化 事件委托篇
<转自 http://www.jb51.net/article/28770.htm> 参考文章: 解密jQuery事件核心 - 绑定设计(一) 参考文章: 解密jQuery事件核心 - ...
- Java中的浅复制和深复制 Cloneable clone
先看一个简单案例 public class Test { public static void main(String args[]) { Student stu1 = new ...