Egret的容器--删除对象,遮罩
生活随笔
收集整理的這篇文章主要介紹了
Egret的容器--删除对象,遮罩
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
class P91F extends egret.Sprite {public constructor() {super();this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);}private onAddToStage(event: egret.Event) {//輕量級容器 DisplayObjectContainer;若在游戲中需要利用容器相關的功能,可以直接創建DisplayObjectContainer類的實例對象//自定義容器,編寫一個類繼承DisplayObjectContainer即可;若要實現graphics相關的,可繼承Sprite//自定義一個容器類,ShapeTest 繼承自egret.Sprite;在文檔類Main中實例化 P91F //實例化代碼 /** 創建場景界面 protected createGameScene(): void {var _shapeTest:P91F = new P91F (); this.addChild(_shapeTest);}*/this.drawTest(event); }private drawTest(evt: egret.Event) {var shp: egret.Shape = new egret.Shape();shp.graphics.beginFill(0x0000ff, 0.8);shp.graphics.drawRect(0, 0, 50, 50);shp.graphics.endFill();shp.graphics.beginFill(0x0000ff, 0.8);shp.graphics.drawRect(50, 50, 50, 50);shp.graphics.endFill();shp.graphics.beginFill(0xff0000, 0.8);shp.graphics.drawRect(50, 0, 50, 50);shp.graphics.endFill();shp.graphics.beginFill(0xff0000, 0.8);shp.graphics.drawRect(0, 50, 50, 50);shp.graphics.endFill();//添加顯示對象到顯示列表:改對象存在,被添加到顯示裂變,在畫面中顯示//addChild就是將對象添加到顯示列表中,顯示列表是一個樹狀結構,這里shp的上一級就是this,就是該類,文檔類是STAGE的第一個子對象this.addChild(shp);//刪除顯示對象:使用removeChild即可刪除一個顯示對象;畫面不顯示,該對象存在,駐于內存中//利用該代碼的時候,建議先判斷是否擁有父級(被刪除的對象在不在顯示列表) if(shp.parent){ 刪除操作;}//this.removeChild(shp);//this是shp的父級,shp是被刪除的顯示對象//遮罩使用:所謂遮罩是指定一個顯示對象的可見區域,在Egret執行渲染的時候,會根據據設置的區域進行裁切,最終得到原始畫面的一部分var rect:egret.Rectangle = new egret.Rectangle( 50,50,300,200);shp.mask = rect;//取消遮罩:將mask屬性設置為nullshp.mask = null;}}
轉載于:https://www.cnblogs.com/allyh/p/10680437.html
總結
以上是生活随笔為你收集整理的Egret的容器--删除对象,遮罩的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [19/04/11-星期四] 多线程_并
- 下一篇: 简单DP (Preparing for