GlobalWaiting.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. export class GlobalWaiting extends fairygui.GComponent
  2. {
  3. img_0:fairygui.GImage;
  4. private _isforcehide:boolean = false;
  5. constructor() { super(); }
  6. protected constructFromXML(xml:any):void
  7. {
  8. this.setSize(fairygui.GRoot.inst.width,fairygui.GRoot.inst.height);
  9. super.constructFromXML(xml);
  10. this.img_0 = this.getChild("img_0").asImage;
  11. this.img_0.visible = false;
  12. this.on(Laya.Event.DISPLAY,this,this.onAddedToStage);
  13. this.on( Laya.Event.UNDISPLAY,this,this.onRemoveFromStage);
  14. }
  15. private _lastTime:number = 0;
  16. private onAddedToStage():void {
  17. this._lastTime = Laya.Browser.now();
  18. Laya.timer.frameLoop(1, this, this.onTimer);
  19. }
  20. private onTimer():void {
  21. if(this.img_0)
  22. {
  23. var nowtime:number = Laya.Browser.now();
  24. var distime:number = nowtime-this._lastTime;
  25. if( distime /1000 >= 0 )
  26. {
  27. if( !this._isforcehide )
  28. {
  29. this.img_0.visible = true;
  30. }
  31. var i:number = this.img_0.rotation;
  32. i += 10;
  33. if(i > 360)
  34. i = i % 360;
  35. this.img_0.rotation = i;
  36. }
  37. else
  38. {
  39. this.img_0.visible = false;
  40. }
  41. }
  42. }
  43. public hideimg():void
  44. {
  45. this._isforcehide = true;
  46. if( this.img_0 )
  47. {
  48. this.img_0.visible = false;
  49. }
  50. }
  51. private onRemoveFromStage():void {
  52. Laya.timer.clear(this, this.onTimer);
  53. }
  54. }