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中的显示 ...
随机推荐
- C++ —— 构建开源的开发环境
目录: 1.开源环境的选择:IDE+编译器 2.构建步骤 1.开源环境的选择:IDE+编译器 在这里选择都是发布在GPL license 下的工具:codeblocks 和 gnu gcc codeb ...
- PHP学习之[第06讲]数组、多维数组和数组函数
一.数组 ①Array(“aa”,12,true,2.2,”test”,50); ②Array(“title”=>“aa”, ”age”=>20); 1.创建: $arr= array( ...
- Java中的字符串流的读取和写入(创建文件并判断重复账户)
各位我又来了!!哎!好心酸!我还没注册到三天!!没法登上博客的首页!!心累!! import java.io.BufferedOutputStream; import java.io.Buffered ...
- Android Rom修改
最近项目里要实现修改开机动画 屏蔽系统桌面等一些涉及到修改底层的功能 一开始研究了一番 心想着看来这是要定制系统 做rom开发了 所以就牛逼哄哄的跑去下源码 研究rom开发 后来发现这将是一个庞大的工 ...
- RxJava RxAndroid【简介】
资源 RxJava:https://github.com/ReactiveX/RxJava RxAndroid :https://github.com/ReactiveX/RxAndroid 官网:h ...
- HTML5 微信二维码提示框
这是一个js的小案例,主要效果是显示一个微信二维码的提示框,非常简单实用. 源码如下: JS部分 <script src="js/jquery-1.8.3.min.js"&g ...
- C#学习第二天
在C#中数据类型大概有两类:值类型和引用类型,需要由定义类型的开发人员决定在什么地方分配一个实例. 值类型和引用类型在使用原理上也有所不同,值类型在使用时是传递或者得到一个值的副本,而引用类型在使用时 ...
- sql查阅每一月的数据
因为项目中需要做数据报表的功能,需要统计每个月的销售额.我找到下面的sql语句.后来经过自己的测试,发现第二句才是可以用的, //String sql="SELECT year(buydat ...
- 二维码生成Demo
在C#中直接引用ThoughtWorks.QRCode.dll 类, 下载 dll 类 http://file.111cn.net/download/2013/06/29/20120516165420 ...
- MD5加密相关
demo效果