熱門文章

Ⓖegret.URLLoader & egret.URLLoaderDataFormat 用法

讀取各種資源方法

var loader: egret.URLLoader = new egret.URLLoader();
loader.dataFormat = egret.URLLoaderDataFormat.TEXTURE; // 材質
loader.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
    var texture: egret.Texture = <egret.Texture>e.target.data;
    this.addChild(new egret.Bitmap(texture));
}, this);
loader.load(new egret.URLRequest("resource/assets/Slider/thumb.png"));

var loader2: egret.URLLoader = new egret.URLLoader();
loader2.dataFormat = egret.URLLoaderDataFormat.TEXT; // 文本
loader2.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
    var text: string = e.target.data;
    (this.addChild(new egret.TextField())).text = text;
}, this);
loader2.load(new egret.URLRequest("resource/config/description.json"));

var loader3: egret.URLLoader = new egret.URLLoader();
loader3.dataFormat = egret.URLLoaderDataFormat.SOUND; // 音樂
loader3.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
    var snd: egret.Sound = <egret.Sound>e.target.data;
    snd.play(); // 瀏覽器限制, 請至少點擊一次遊戲畫面此方法才能生效
}, this);
loader3.load(new egret.URLRequest("resource/assets/bg.mp3"));

沒有留言:

張貼留言