使用白鷺引擎遇到的一些問題以及一些工具分享

用egret也有一段時間了,記錄一下遇到的bug和流水帳。html

 

BUG類android

1 Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data. web

egret 2.5 裏面將WebImageLoader的crossOrigin默認值設置爲anonymous就能夠了json

 

Update:2017-11-30 canvas

緩存資源進入遊戲可是顯示不正常的問題

棋牌項目裏面加載和卸載遊戲模塊的時候,退出遊戲的時候緩存資源卸載js程序。瀏覽器

從新進入遊戲的時候,部分資源沒法顯示出來,可是點擊相應位置仍是有響應。緩存

在console裏面經過RES.getRes(resname)的方法獲得一個顯示正常的Texture一個不正常的Texture,服務器

對比發現,顯示正常的bitmapdata的sourc是一個img,而顯示不正常的bitmapdata的source是null。ide

而後在egret.js的bitmap裏面斷點的時候發現,因爲使用了sheet裏面的元素的顯示對象調用了texture.dispose(),致使銷燬了texture。工具

因此使用了圖集裏面的元素的全部顯示對象的bitmapdata數據基本正確,可是就source是空,而顯示不正常。

而後在整個項目中搜索texture.dispose(),註釋掉就行了。

資源若是不要緩存的話,應該仍是要在調用了RES.destroyRes後強行dispose一下。

 

 

Update:2017-9-21

從別的項目取來的exml文件不能用的問題

在wing3,egret 5.0.3中,
default.thm.json中沒法被自動加載,
即便手動去其中添加也會在build的時候被清理掉。
由於新生成的項目的egretProperties.json中有默認配置:

"eui": {
"exmlRoot": "resource/eui_skins", "themes": [ "resource/default.thm.json" ] },

這裏應該是eui皮膚文件的配置,

把這裏刪除掉,

而後使用egret清理就能夠看到全部皮膚文件導入進來了。

設置了分辨率但build以後大小仍是默認的

egret項目文件裏有一個叫作template的文件夾,

其中有debug,runtime和web三個文件夾,

本地調試能夠修改debug裏面的index.html的尺寸和其餘數據就能夠在build以後顯示正常。

 

 2016-1-8【如下應該是egret版本 <= 3.0】

egret.gui.BitmapLabel自定義font不能居中問題

在egret wing裏面設置textAlign是經過setStyle去生效的,這個沒有附加到BitmapLabel._bitmapText上去,由於BitmapLabel._bitmapText是經過_addToDisplayList()的方式去加上去的,這是官方比較hack的方式去將非UIComponent的元件加到gui顯示列表裏面去,因此這個style是沒法生效的,個人解決方法很簡單,直接給BitmapLabel加textAlign的setter和getter,而後在commiteProperties()裏面判斷textAlign是否有變動,有的話就賦值給BitmapLabel._bitmapText.textAlign,這個方法只能在程序裏面手動去設置,egret wing裏面的設置仍是無效的,問題解決,修改後的BitmapLabel.ts以下:

  1 //////////////////////////////////////////////////////////////////////////////////////
  2 //
  3 //  Copyright (c) 2014-2015, Egret Technology Inc.
  4 //  All rights reserved.
  5 //  Redistribution and use in source and binary forms, with or without
  6 //  modification, are permitted provided that the following conditions are met:
  7 //
  8 //     * Redistributions of source code must retain the above copyright
  9 //       notice, this list of conditions and the following disclaimer.
 10 //     * Redistributions in binary form must reproduce the above copyright
 11 //       notice, this list of conditions and the following disclaimer in the
 12 //       documentation and/or other materials provided with the distribution.
 13 //     * Neither the name of the Egret nor the
 14 //       names of its contributors may be used to endorse or promote products
 15 //       derived from this software without specific prior written permission.
 16 //
 17 //  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 18 //  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 19 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20 //  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 21 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 22 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
 23 //  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 24 //  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 25 //  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 26 //  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 //
 28 //////////////////////////////////////////////////////////////////////////////////////
 29 
 30 
 31 module egret.gui {
 32 
 33     /**
 34      * @class egret.gui.BitmapLabel
 35      * @classdesc
 36      * 一行或多行不可編輯的位圖文本控件
 37      * @extends egret.gui.UIComponent
 38      */
 39     export class BitmapLabel extends UIComponent implements IDisplayText {
 40 
 41         private _bitmapText:BitmapText = null;
 42 
 43         /**
 44          * @method egret.gui.Label#constructor
 45          */
 46         public constructor() {
 47             super();
 48             this.addEventListener(UIEvent.UPDATE_COMPLETE, this.updateCompleteHandler, this);
 49         }
 50 
 51         /**
 52          * 一個驗證階段完成
 53          */
 54         private updateCompleteHandler(event:UIEvent):void {
 55             this.lastUnscaledWidth = NaN;
 56         }
 57 
 58         private _textChanged:boolean = false;
 59         private _text:string = "";
 60         /**
 61          * @member egret.gui.BitmapLabel#text
 62          * 設置或獲取顯示文本
 63          */
 64         public set text(value:string) {
 65             if (this._text == value)
 66                 return;
 67             this._text = value;
 68             this._textChanged = true;
 69             this.invalidateProperties();
 70             this.invalidateSize();
 71             this.invalidateDisplayList();
 72         }
 73 
 74         public get text():string {
 75             return this._text;
 76         }
 77 
 78         private fontChanged:boolean = false;
 79 
 80         public _font:any;
 81         /**
 82          * 位圖字體標識符,能夠是BitmapFont對象或者在資源表中的key。
 83          * @member egret.gui.BitmapLabel#font
 84          */
 85         public get font():any {
 86             return this._font;
 87         }
 88 
 89         public set font(value:any) {
 90             if (this._font == value)
 91                 return;
 92             this._font = value;
 93             if (this.createChildrenCalled) {
 94                 this.parseFont();
 95             }
 96             else {
 97                 this.fontChanged = true;
 98             }
 99             this.invalidateProperties();
100             this.invalidateSize();
101             this.invalidateDisplayList();
102         }
103 
104         private _isLetterSpacingChanged:boolean = false;
105         public _letterSpacing:number = 0;
106         /**
107          * 字符之間的距離
108          * @default 0
109          * @param value
110          */
111         public set letterSpacing(value:number) {
112             this._setLetterSpacing(value);
113         }
114 
115         public _setLetterSpacing(value:number):void {
116             this._letterSpacing = value;
117 
118             this._isLetterSpacingChanged = true;
119             this.invalidateProperties();
120             this.invalidateSize();
121             this.invalidateDisplayList();
122         }
123 
124         public get letterSpacing():number {
125             return this._letterSpacing;
126         }
127         
128         private _isTextAlignChanged:boolean = false;
129         public _textAlign:string = "left";
130         /**
131          * 字符之間的距離
132          * @default 0
133          * @param value
134          */
135         public set textAlign(value:string) {
136             this._settextAlign(value);
137         }
138 
139         public _settextAlign(value:string):void {
140             this._textAlign = value;
141 
142             this._isTextAlignChanged = true;
143             this.invalidateProperties();
144             this.invalidateSize();
145             this.invalidateDisplayList();
146         }
147 
148         public get textAlign():string {
149             return this._textAlign;
150         }
151 
152         private _isLineSpacingChanged:boolean = false;
153         public _lineSpacing:number = 0;
154         /**
155          * 行與行之間的距離
156          * @default 0
157          * @param value
158          */
159         public set lineSpacing(value:number) {
160             this._setLineSpacing(value);
161         }
162 
163         public _setLineSpacing(value:number):void {
164             this._lineSpacing = value;
165 
166             this._isLineSpacingChanged = true;
167             this.invalidateProperties();
168             this.invalidateSize();
169             this.invalidateDisplayList();
170         }
171 
172         public get lineSpacing():number {
173             return this._lineSpacing;
174         }
175 
176         private createChildrenCalled:boolean = false;
177 
178         /**
179          * 建立子對象
180          */
181         public createChildren():void {
182             super.createChildren();
183             if (!this._bitmapText) {
184                 this.checkBitmapText();
185             }
186             if (this.fontChanged) {
187                 this.parseFont();
188             }
189             this.createChildrenCalled = true;
190         }
191 
192         /**
193          * 皮膚解析適配器
194          */
195         private static assetAdapter:IAssetAdapter;
196 
197         /**
198          * 解析source
199          */
200         private parseFont():void {
201             this.fontChanged = false;
202             var adapter:IAssetAdapter = BitmapLabel.assetAdapter;
203             if (!adapter) {
204                 adapter = this.getAdapter();
205             }
206             if (!this._font) {
207                 this.onFontChanged(null, null);
208             }
209             else {
210                 adapter.getAsset(this._font, this.onFontChanged, this, null);
211             }
212         }
213 
214         /**
215          * 獲取資源適配器
216          */
217         private getAdapter():IAssetAdapter {
218             var adapter:IAssetAdapter;
219             try {
220                 adapter = $getAdapter("egret.gui.IAssetAdapter");
221             }
222             catch (e) {
223                 adapter = new DefaultAssetAdapter();
224             }
225             BitmapLabel.assetAdapter = adapter;
226             return adapter;
227         }
228 
229         /**
230          * 皮膚髮生改變
231          */
232         private onFontChanged(bitmapFont:any, font:any):void {
233             if (font !== this._font)
234                 return;
235             this._bitmapText.font = bitmapFont;
236             this.invalidateSize();
237             this.invalidateDisplayList();
238         }
239 
240 
241         /**
242          * 上一次測量的寬度
243          */
244         private lastUnscaledWidth:number = NaN;
245 
246         private _padding:number = 0;
247         /**
248          * 四個邊緣的共同內邊距。若單獨設置了任一邊緣的內邊距,則該邊緣的內邊距以單獨設置的值爲準。
249          * 此屬性主要用於快速設置多個邊緣的相同內邊距。默認值:0。
250          * @member egret.gui.BitmapLabel#padding
251          */
252         public get padding():number {
253             return this._padding;
254         }
255 
256         public set padding(value:number) {
257             if (this._padding == value)
258                 return;
259             this._padding = value;
260             this.invalidateSize();
261             this.invalidateDisplayList();
262         }
263 
264         private _paddingLeft:number = NaN;
265         /**
266          * 文字距離左邊緣的空白像素,若爲NaN將使用padding的值,默認值:NaN。
267          * @member egret.gui.BitmapLabel#paddingLeft
268          */
269         public get paddingLeft():number {
270             return this._paddingLeft;
271         }
272 
273         public set paddingLeft(value:number) {
274             if (this._paddingLeft == value)
275                 return;
276 
277             this._paddingLeft = value;
278             this.invalidateSize();
279             this.invalidateDisplayList();
280         }
281 
282         /**
283          *
284          * @type {number}
285          * @private
286          */
287         private _paddingRight:number = NaN;
288         /**
289          * 文字距離右邊緣的空白像素,若爲NaN將使用padding的值,默認值:NaN。
290          * @member egret.gui.BitmapLabel#paddingRight
291          */
292         public get paddingRight():number {
293             return this._paddingRight;
294         }
295 
296         public set paddingRight(value:number) {
297             if (this._paddingRight == value)
298                 return;
299 
300             this._paddingRight = value;
301             this.invalidateSize();
302             this.invalidateDisplayList();
303         }
304 
305         /**
306          *
307          * @type {number}
308          * @private
309          */
310         private _paddingTop:number = NaN;
311         /**
312          * 文字距離頂部邊緣的空白像素,若爲NaN將使用padding的值,默認值:NaN。
313          * @member egret.gui.BitmapLabel#paddingTop
314          */
315         public get paddingTop():number {
316             return this._paddingTop;
317         }
318 
319         public set paddingTop(value:number) {
320             if (this._paddingTop == value)
321                 return;
322 
323             this._paddingTop = value;
324             this.invalidateSize();
325             this.invalidateDisplayList();
326         }
327 
328         /**
329          *
330          * @type {number}
331          * @private
332          */
333         private _paddingBottom:number = NaN;
334         /**
335          * 文字距離底部邊緣的空白像素,若爲NaN將使用padding的值,默認值:NaN。
336          * @member egret.gui.BitmapLabel#paddingBottom
337          */
338         public get paddingBottom():number {
339             return this._paddingBottom;
340         }
341 
342         public set paddingBottom(value:number) {
343             if (this._paddingBottom == value)
344                 return;
345 
346             this._paddingBottom = value;
347             this.invalidateSize();
348             this.invalidateDisplayList();
349         }
350 
351         /**
352          * 計算  容器默認大小的最小值和最大值
353          * @method egret.gui.BitmapLabel#measure
354          */
355         public measure():void {
356             //先提交屬性,防止樣式發生改變致使的測量不許確問題。
357             if (this._UIC_Props_._invalidatePropertiesFlag)
358                 this.validateProperties();
359             if (this.isSpecialCase()) {
360                 if (isNaN(this.lastUnscaledWidth)) {
361                     this._UIC_Props_._oldPreferWidth = NaN;
362                     this._UIC_Props_._oldPreferHeight = NaN;
363                 }
364                 else {
365                     this.measureUsingWidth(this.lastUnscaledWidth);
366                     return;
367                 }
368             }
369 
370             var availableWidth:number;
371 
372             if (!isNaN(this.$getExplicitWidth())) {
373                 availableWidth = this.$getExplicitWidth();
374             }
375             else if (this.maxWidth != 10000)
376                 availableWidth = this.maxWidth;
377 
378             this.measureUsingWidth(availableWidth);
379         }
380 
381         /**
382          * 特殊狀況,組件尺寸由父級決定,要等到父級UpdateDisplayList的階段才能測量
383          */
384         private isSpecialCase():boolean {
385             return (!isNaN(this.percentWidth) || (!isNaN(this.left) && !isNaN(this.right))) &&
386                 isNaN(this.$getExplicitWidth()) &&
387                 isNaN(this.percentHeight);
388         }
389 
390         /**
391          * 使用指定的寬度進行測量
392          */
393         private measureUsingWidth(w:number):void {
394             if (this._textChanged) {
395                 this._bitmapText.text = this._text;
396             }
397 
398             if (this._isLetterSpacingChanged) {
399                 this._bitmapText.letterSpacing = this._letterSpacing;
400             }
401             if (this._isLineSpacingChanged) {
402                 this._bitmapText.lineSpacing = this._lineSpacing;
403             }
404             if( this._isTextAlignChanged){
405                 this._bitmapText.textAlign = this._textAlign;
406             }
407 
408             var padding:number = isNaN(this._padding) ? 0 : this._padding;
409             var paddingL:number = isNaN(this._paddingLeft) ? padding : this._paddingLeft;
410             var paddingR:number = isNaN(this._paddingRight) ? padding : this._paddingRight;
411             var paddingT:number = isNaN(this._paddingTop) ? padding : this._paddingTop;
412             var paddingB:number = isNaN(this._paddingBottom) ? padding : this._paddingBottom;
413 
414             this._bitmapText.width = NaN;
415             this._bitmapText.height = NaN;
416             if (!isNaN(w)) {
417                 this._bitmapText.width = w - paddingL - paddingR;
418                 this.measuredWidth = Math.ceil(this._bitmapText.width);
419                 this.measuredHeight = Math.ceil(this._bitmapText.height);
420             }
421             else {
422                 this.measuredWidth = Math.ceil(this._bitmapText.width);
423                 this.measuredHeight = Math.ceil(this._bitmapText.height);
424             }
425             this.measuredWidth += paddingL + paddingR;
426             this.measuredHeight += paddingT + paddingB;
427 
428         }
429 
430         /**
431          * 經過設置此容器子項的位置和大小來響應大小更改
432          * @method egret.gui.BitmapLabel#updateDisplayList
433          * @param unscaledWidth {number}
434          * @param unscaledHeight {number}
435          */
436         public updateDisplayList(unscaledWidth:number, unscaledHeight:number):void {
437             super.updateDisplayList(unscaledWidth, unscaledHeight);
438             if (!this._bitmapText)
439                 return;
440             var padding:number = isNaN(this._padding) ? 0 : this._padding;
441             var paddingL:number = isNaN(this._paddingLeft) ? padding : this._paddingLeft;
442             var paddingR:number = isNaN(this._paddingRight) ? padding : this._paddingRight;
443             var paddingT:number = isNaN(this._paddingTop) ? padding : this._paddingTop;
444             var paddingB:number = isNaN(this._paddingBottom) ? padding : this._paddingBottom;
445 
446             this._bitmapText.x = paddingL;
447             this._bitmapText.y = paddingT;
448             if (this.isSpecialCase()) {
449                 var firstTime:boolean = isNaN(this.lastUnscaledWidth) ||
450                     this.lastUnscaledWidth != unscaledWidth;
451                 this.lastUnscaledWidth = unscaledWidth;
452                 if (firstTime) {
453                     this._UIC_Props_._oldPreferWidth = NaN;
454                     this._UIC_Props_._oldPreferHeight = NaN;
455                     this.invalidateSize();
456                     return;
457                 }
458             }
459             //防止在父級validateDisplayList()階段改變的text屬性值,
460             //接下來直接調用自身的updateDisplayList()而沒有通過measure(),使用的測量尺寸是上一次的錯誤值。
461             if (this._UIC_Props_._invalidateSizeFlag)
462                 this.validateSize();
463 
464             if (!this._bitmapText.visible)//解決初始化時文本閃爍問題
465                 this._bitmapText.visible = true;
466 
467             this._bitmapText.width = unscaledWidth - paddingL - paddingR;
468             var unscaledTextHeight:number = unscaledHeight - paddingT - paddingB;
469             this._bitmapText.height = unscaledTextHeight;
470 
471         }
472 
473         private checkBitmapText() {
474             if (this._bitmapText)
475                 return;
476             this._bitmapText = new BitmapText();
477             this._bitmapText.text = this._text;
478             this._bitmapText.letterSpacing = this._letterSpacing;
479             this._bitmapText.lineSpacing = this._lineSpacing;
480             this._bitmapText.textAlign = this._textAlign;
481             this._textChanged = false;
482             this._isLetterSpacingChanged = false;
483             this._isLineSpacingChanged = false;
484             this._isTextAlignChanged = false;
485             this._addToDisplayList(this._bitmapText);
486         }
487 
488         /**
489          * 處理對組件設置的屬性
490          */
491         public commitProperties():void {
492             super.commitProperties();
493 
494             if (!this._bitmapText) {
495                 this.checkBitmapText();
496             }
497             if (this._textChanged) {
498                 this._bitmapText.text = this._text;
499                 this._textChanged = false;
500             }
501             if (this._isLetterSpacingChanged) {
502                 this._bitmapText.letterSpacing = this._letterSpacing;
503                 this._isLetterSpacingChanged = false;
504             }
505             if (this._isLineSpacingChanged) {
506                 this._bitmapText.lineSpacing = this._lineSpacing;
507                 this._isLineSpacingChanged = false;
508             }
509             if (this._isTextAlignChanged) {
510                 this._bitmapText.textAlign = this._textAlign;
511                 this._isTextAlignChanged = false;
512             }
513         }
514 
515     }
516 }
BitmapLabel.ts

Sound.play()循環播放致使聲音重複加載的問題

產生的緣由是HtmlSoundChannel.ts在播放完成的時候,判斷到loops的時候,直接從新this.audio.load(),而後瀏覽器去進行了加載,至於瀏覽器爲何不是從緩存裏面去加載而是去服務器上加載,我就不知道了,我只知道,判斷一下而後去肯定是否要去加載,治癒官方說的有的手機會播放不了,對於大型遊戲,例如咱們項目來講,其實聲音在大部分機型上能播放就能夠了,最起碼我是這麼認爲的:

  1 //////////////////////////////////////////////////////////////////////////////////////
  2 //
  3 //  Copyright (c) 2014-2015, Egret Technology Inc.
  4 //  All rights reserved.
  5 //  Redistribution and use in source and binary forms, with or without
  6 //  modification, are permitted provided that the following conditions are met:
  7 //
  8 //     * Redistributions of source code must retain the above copyright
  9 //       notice, this list of conditions and the following disclaimer.
 10 //     * Redistributions in binary form must reproduce the above copyright
 11 //       notice, this list of conditions and the following disclaimer in the
 12 //       documentation and/or other materials provided with the distribution.
 13 //     * Neither the name of the Egret nor the
 14 //       names of its contributors may be used to endorse or promote products
 15 //       derived from this software without specific prior written permission.
 16 //
 17 //  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 18 //  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 19 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20 //  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 21 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 22 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
 23 //  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 24 //  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 25 //  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 26 //  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 //
 28 //////////////////////////////////////////////////////////////////////////////////////
 29 
 30 module egret.web {
 31 
 32     /**
 33      * @private
 34      * @inheritDoc
 35      */
 36     export class HtmlSoundChannel extends egret.EventDispatcher implements egret.SoundChannel {
 37 
 38 
 39         /**
 40          * @private
 41          */
 42         $url:string;
 43         /**
 44          * @private
 45          */
 46         $loops:number;
 47         /**
 48          * @private
 49          */
 50         $startTime:number = 0;
 51         /**
 52          * @private
 53          */
 54         private audio:HTMLAudioElement = null;
 55 
 56         //聲音是否已經播放完成
 57         private isStopped:boolean = false;
 58 
 59         /**
 60          * @private
 61          */
 62         constructor(audio:HTMLAudioElement) {
 63             super();
 64             audio.addEventListener("ended", this.onPlayEnd);
 65             this.audio = audio;
 66         }
 67 
 68         $play():void {
 69             if (this.isStopped) {
 70                 egret.$error(1036);
 71                 return;
 72             }
 73 
 74             try {
 75                 this.audio.currentTime = this.$startTime;
 76             }
 77             catch (e) {
 78 
 79             }
 80             finally {
 81                 this.audio.play();
 82             }
 83         }
 84 
 85         /**
 86          * @private
 87          */
 88         private onPlayEnd = () => {
 89             if (this.$loops == 1) {
 90                 this.stop();
 91 
 92                 this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
 93                 return;
 94             }
 95 
 96             if (this.$loops > 0) {
 97                 this.$loops--;
 98             }
 99 
100             /////////////
101             if( !this.audio.ended)
102                 this.audio.load();
103             this.$play();
104         };
105 
106         /**
107          * @private
108          * @inheritDoc
109          */
110         public stop() {
111             if (!this.audio)
112                 return;
113             var audio = this.audio;
114             audio.pause();
115             audio.removeEventListener("ended", this.onPlayEnd);
116             this.audio = null;
117 
118             HtmlSound.$recycle(this.$url, audio);
119         }
120 
121         /**
122          * @private
123          * @inheritDoc
124          */
125         public get volume():number {
126             if (!this.audio)
127                 return 1;
128             return this.audio.volume;
129         }
130 
131         /**
132          * @inheritDoc
133          */
134         public set volume(value:number) {
135             if (this.isStopped) {
136                 egret.$error(1036);
137                 return;
138             }
139 
140             if (!this.audio)
141                 return;
142             this.audio.volume = value;
143         }
144 
145         /**
146          * @private
147          * @inheritDoc
148          */
149         public get position():number {
150             if (!this.audio)
151                 return 0;
152             return this.audio.currentTime;
153         }
154     }
155 }
HtmlSoundChannel.ts

 QQ玩吧聲音加載和播放問題

Android QQ玩吧的頁面若是有嵌入jsbridge.js的話,egret會判斷是不是玩吧,時候有jsbridge裏面的接口,有的話會強制使用相對路徑,詳見HtmlCapbility搜索"wanba"就能夠看到了,此時玩吧會使用他們的audio播放程序去加載和播放audio,cdn以及絕對路徑都會沒有用,resource必定要存放在代碼的相對根目錄下才能用。

全部細節能夠參考:HtmlCapability以及QQSound中參考

解決方法很簡單,去掉頁面裏面的jsbridge.js的嵌入,其實這個js文件沒有什麼用,去掉後android上QQ玩吧會默認使用egret.HtmlSound去播放聲音

 

心得

關閉列表的滾動:比較hack的作法

var skin = this.list.skin;
var scroller:egret.gui.Scroller = skin._elementsContent[0]; if( scroller != null) scroller.verticalScrollPolicy = "off";

監聽列表的滾動事件

這個找了好久

this.list.dataGroup.addEventListener(egret.gui.PropertyChangeEvent.PROPERTY_CHANGE,this.onListTouchEnd, this);

private onListTouchEnd(evt:egret.gui.PropertyChangeEvent){

            var newPos:number = evt.newValue; var referPos:number = this.list.dataGroup.scrollRect.bottom-this.list.dataGroup.height; if( evt.property == "verticalScrollPosition" && referPos - newPos <= 10){ //todo dosomething  } }

 

 

 

工具

1 抽屜效果

原理: Tween + mask實現

例如對顯示對象d實現抽屜效果:

var tw:egret.Tween = egret.Tween.get(this.d,{onChange:this.updateMask,onChangeObj:this},null,true);
this.maskForD = new egret.Rectangle(0,0,0,60);
private updateMask(){ var showWidth:number; if( this.isLeft){ showWidth = 420-(this.itemGroup.x-20); }else{ showWidth = 420 - this.itemGroup.x; } this.maskForD.width = showWidth; this.d.mask = this.maskForItemGroup; }

 

2 幀事件的管理

沿用as的習慣,全局只有一個幀事件。

FrameMgr

配合這個使用:

FrameItem

3 簡單的位移補間

用自帶的Tween效率不是很好,因而本身實現了一個,以下:

MoveMgr

須要配合這個使用:

MoveItem

4 作了一個簡單的重力系統,以下:

GravitySystem

配合使用的類:

View Code
相關文章
相關標籤/搜索