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中的显示 ...
随机推荐
- CentOS-6.4-i386硬盘安装
由于安装程序不能识别NTFS分区上的镜像,因此需要变通,网上可参考的文章分为两种方法: 1.使用分区工具创建EXT分区,再用Windows下可访问EXT分区的软件,将安装镜像拷入进行安装. 2.使用分 ...
- top -bcn -1
^[[?1h^[=^[[?25l^[[H^[[2J^[(B^[[mtop #!/bin/bash#echo 性能数据捕捉时间: `date +%Y-%m-%d_%H:%M:%S` \n >> ...
- kvm编译安装及常见问题解决
一.KVM的编译安装 1.安装基本系统和开发工具 1.1 编译内核 mkdir /root/kvm cd /root/kvm wget http://www.kernel.org/pub/linux/ ...
- 6种GET和POST请求发送方法
我试过了畅言和多说两种社会化评论框,后来还是抛弃了畅言,不安全. 无论是畅言还是多说,我都需要从远程抓取文章的评论数,然后存入本地数据库.对于多说,请求的格式如下: // 获取评论次数,参数是文章ID ...
- 函数调用和给对象发消息(Runtime理解)
在写代码的时候这个差距其实是不打看的出得,很多时候也就无所谓叫什么,很多人为了便于理解,干脆就叫函数调用.这个其实应该是oc的一个特色,消息发送.具体的类typedef struct objc_cla ...
- 11th day
今天MySQL数据库的基本知识就学完了,明天开始做小项目什么的,有点小激动啊... <?php // 定义$sql语句执行函数 function my_query($sql){ $result ...
- 小菜学习Lucene.Net(更新3.0.3版本使用)
花了两天的时间研究了下Lucene.Net 发现确实挺好玩.... 最新版本是3.0.3 (最后更新时间2012-10) 可惜3.0.3版本的Lucene.net无法和盘古分词 (最新版为2.3.1. ...
- Android MVC框架模式
MCV model view controller 模型-视图-控制写 M层:适合做一些业务逻辑处理,比如数据库存取操作,网络操作,复杂的算法,耗时的任务等都在model层处理. V层:应用层中处 ...
- cocos2d-x项目过程记录(cocos2d-x的新知)
1.给CCMenuItem带上点击参数(这是CCNode的一个属性) CCMenuItem *item = CCMenuItemSprite::create(unselectedPic, select ...
- Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
1. Collection集合的基本功能测试: package cn.itcast_01; import java.util.ArrayList; import java.util.Collectio ...