关于gui的skinnableContainer的一点问题
生活随笔
收集整理的這篇文章主要介紹了
关于gui的skinnableContainer的一点问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建一個UIAsset
var uiAsset = new egret.gui.UIAsset();uiAsset.source = "bgImage";把UIAsset添加到SkinnableContainer上
var container = new egret.gui.SkinnableContainer();container.addElement(uiAsset);然后把container添加到stage上會發現uiAsset并沒有顯示出來。這是什么原因呢?
這時我去看了一下SkinnableContainer的代碼,發現
public addElement(element:IVisualElement):IVisualElement {return this._getCurrentContentGroup().addElement(element); }public _getCurrentContentGroup():Group {if (this.contentGroup == null) {if (this._placeHolderGroup == null) {this._placeHolderGroup = new Group();this._placeHolderGroup.visible = false;this._addToDisplayList(<DisplayObject><any>this._placeHolderGroup);}this._placeHolderGroup.addEventListener(ElementExistenceEvent.ELEMENT_ADD, this._contentGroup_elementAddedHandler, this);this._placeHolderGroup.addEventListener(ElementExistenceEvent.ELEMENT_REMOVE, this._contentGroup_elementRemovedHandler, this);return this._placeHolderGroup;}else {return this.contentGroup; } }SkinnableContainer的addElement是默認如果沒有contentGroup的話是加在_placeHolderGroup上的,而placeHolderGroup默認的visible是false的,而在partAdded中如果發現有皮膚里有contentGroup,則會把placeHolderGroup的children放到contentGroup里。
皮膚里若沒有contentGroup,則skinnableContainer所有的addElement的子項都不會顯示。
我們給container賦一個皮膚。
var container = new egret.gui.SkinnableContainer();container.skinName = testSkin;container.addElement(uiAsset);//皮膚類 class testSkin extends egret.gui.Skin {private contentGroup:egret.gui.Group;public get skinParts() {return ["contentGroup"]}constructor() {super();}public createChildren():void {super.createChildren();var group = new egret.gui.Group();this.contentGroup = group;this.addElement(group);} }testSkin當中有一個contentGroup,這樣uiAsset才會顯示出來。
轉載于:https://www.cnblogs.com/guessWhat/p/4306331.html
總結
以上是生活随笔為你收集整理的关于gui的skinnableContainer的一点问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Bluetooth LE(低功耗蓝牙)
- 下一篇: RethinkDB创始人教你如何打造一个