美素佳儿 litter wizard小游戏
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

5 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * Copyright (c) 2014,www.easygame.org
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the easygame.org nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. class Main extends egret.DisplayObjectContainer {
  28. /**
  29. * 加载进度界面
  30. * Process interface loading
  31. */
  32. private loadingMain:virus.LoadMianProgressMainBar;//loading main
  33. //RES资源全部下载完成
  34. private loadResAllComplete:boolean = false;
  35. //easy game的配置文件时候下载完成
  36. private _isEasyGameOk:boolean = false;//游戏配置下载完毕
  37. private _isSoundOk:boolean = false;//声音准备完毕
  38. private _isProjectUIOk:boolean = false;//公用UI下载完毕
  39. private _isCreateScene:boolean = false//是否已创建场景
  40. private _isLoadingViewOk:boolean = false;//view的loading是否准备好了
  41. private _progressCalculate:easy.ProgressCalculate = null;
  42. private _isViewEnter:boolean = false;//第一个加载的view是否已经准备完成
  43. public constructor() {
  44. super();
  45. this.loadResAllComplete = false;
  46. this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
  47. }
  48. private onAddToStage(event: egret.Event) {
  49. egret.ImageLoader.crossOrigin = "anonymous";
  50. //初始化全局数据,以便Heatbeat可以使用
  51. easy.GlobalSetting.initData();
  52. //初始化Resource资源加载库
  53. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "loading_main.json", ["loading_main"], this.onResLoadingMianComplete,this);
  54. //下载loading view的内容
  55. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "loading_view.json", ["loading_view"], this.onResLoadingViewComplete,this);
  56. easy.EventManager.addEventListener(easy.EventType.VIEW_ENTER, this.onHiddenloadingMain, this);
  57. }
  58. /**
  59. * loading view配置文件的加载完成
  60. * @param event
  61. */
  62. private onResLoadingViewComplete(event:RES.ResourceEvent):void{
  63. this._isLoadingViewOk = true;
  64. }
  65. /**
  66. * loading main配置文件的加载完成
  67. * @param event
  68. */
  69. private onResLoadingMianComplete(event:RES.ResourceEvent):void{
  70. //console.log("@Main onLoadingMianResourceLoadComplete=" + event.groupName);
  71. if(RES.isGroupLoaded("loading_main")){
  72. //设置加载进度界面
  73. this.loadingMain = new virus.LoadMianProgressMainBar();//loading main
  74. this.stage.addChild(this.loadingMain);
  75. this.loadingMain.width = easy.GlobalSetting.DISPLAY_WIDTH;
  76. this.loadingMain.height = easy.GlobalSetting.DISPLAY_HEIGHT;
  77. this.loadingMain.enter();
  78. //启动进度条计数
  79. this._progressCalculate = new easy.ProgressCalculate(10);
  80. easy.HeartBeat.addListener(this,this.onHbProgress,2);
  81. //初始化Resource资源加载库
  82. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "resource.json", ["group_easygame_config"], this.onResLoadGameConfigComplete, this);
  83. //提前加载Json数据,创建场景的时候,可能就需要用到数据了
  84. //virus.DataManager.loadJsonFile();
  85. //加载公用资源,如果设置有公用资源请打开此项
  86. //easy.ResManager.loadResFile("virus");
  87. //easy.EventManager.addEventListener(easy.EventType.PROJECT_RES_DOWNLOADED, this.onProjectResDownloaded, this);
  88. this._isProjectUIOk = true;
  89. }
  90. }
  91. /**
  92. * 控制进度条
  93. * @type {number}
  94. */
  95. private onHbProgress():void{
  96. var progress:number = this._progressCalculate.progress();
  97. this._progressCalculate._progressSpeedUp = (this.loadResAllComplete && this._isProjectUIOk && this._isViewEnter);
  98. this.loadingMain.setProgress(progress,100);
  99. if (this.loadResAllComplete && !this._isCreateScene && this._isLoadingViewOk) this.createScene();
  100. if (progress == 100) {
  101. easy.HeartBeat.removeListener(this, this.onHbProgress);
  102. this.removeLoadingUI();
  103. }
  104. }
  105. /**
  106. * 将loading页面移除,开始创建场景
  107. */
  108. private removeLoadingUI():void{
  109. if (this.loadingMain) {
  110. this.loadingMain.outer();
  111. }
  112. }
  113. /**
  114. * 公用资源加载完成的通知
  115. * @param myEvent
  116. */
  117. private onProjectResDownloaded(myEvent:easy.MyEvent):void {
  118. easy.EventManager.removeEventListener(easy.EventType.PROJECT_RES_DOWNLOADED, this.onProjectResDownloaded, this);
  119. this._isProjectUIOk = true;
  120. this.checkAllResourceLoaded();
  121. }
  122. /**
  123. * preload资源组加载完成
  124. */
  125. private onResLoadGameConfigComplete(event:RES.ResourceEvent):void {
  126. //console.log("@Main onResourceLoadComplete=" + event.groupName);
  127. if(RES.isGroupLoaded("group_easygame_config")) {
  128. this._isEasyGameOk = true;
  129. //下载全部完成
  130. //设置帧频
  131. easy.GlobalSetting.FRAME_RATE = 60;
  132. //EasyGame初始化
  133. easy.EasyGame.init();
  134. //设置界面切换的loading,view的loading和Win的loading可以设置成不一样的类
  135. easy.ViewManager.defaultLoadingClass = virus.LoadViewProgressViewBar;//loading view
  136. easy.PopupManager.defaultLoadingClass = virus.LoadViewProgressViewBar;//loading view
  137. }
  138. this.checkAllResourceLoaded();
  139. }
  140. /**
  141. * 声音加载完成
  142. */
  143. private onResLoadSoundComplete(event:RES.ResourceEvent):void {
  144. //console.log("@Main onResourceLoadComplete=" + event.groupName);
  145. if(RES.isGroupLoaded("sound")) {
  146. this._isSoundOk = true;
  147. //声音加载完毕,播放背景音文件
  148. //easy.Sound.play("sound_bg", 0 , 0);
  149. }
  150. }
  151. /**
  152. * 检测是否所有需要的资源全部加载完成
  153. * 下载全部完成的情况下设置loadAllComplete标志,等待loading的全部反应
  154. */
  155. private checkAllResourceLoaded():void {
  156. if(this._isEasyGameOk && this._isProjectUIOk){
  157. //创建场景
  158. if (easy.GlobalSetting.APP_STORAGE == easy.GlobalSetting.STORAGE_NET || easy.GlobalSetting.APP_STORAGE == easy.GlobalSetting.STORAGE_LOCAL_NET){
  159. this.loadDataFromNet();
  160. } else{
  161. this.loadResAllComplete = true;
  162. }
  163. }
  164. }
  165. /**
  166. * 隐藏加载进度条
  167. */
  168. private onHiddenloadingMain(myEvent:easy.MyEvent):void {
  169. this._isViewEnter = true;
  170. easy.EventManager.removeEventListener(easy.EventType.VIEW_ENTER, this.onHiddenloadingMain, this);
  171. //声音加载
  172. //easy.ResManager.addGroupCompleteListener("sound", this.onResLoadSoundComplete, this);
  173. }
  174. /**
  175. * 需要从网络初始化信息
  176. */
  177. private loadDataFromNet():void {
  178. //TODO 这里填写需要网络加载的信息,完成后,请调用loadDataFromNetComplete()方法,加载主场景
  179. //this.loadDataFromNetComplete();
  180. }
  181. /**
  182. * 从网络加载初始化信息完成
  183. */
  184. private loadDataFromNetComplete():void {
  185. //TODO 网络信息的初始化,请在这里填写
  186. this.loadResAllComplete = true;
  187. }
  188. /**
  189. * 创建场景
  190. */
  191. private createScene():void{
  192. if (this._isCreateScene) return;//防止多次创建
  193. this._isCreateScene = true;
  194. //console.log("main.createScene")
  195. //TODO 提前预设空闲下载,加快后续的模块载入速度
  196. easy.ResManager.addIdleDownload(virus.temp_gameTemplate);
  197. easy.ResManager.addIdleDownload(virus.temp_rankTemplate);
  198. //TODO 动画的预加载方式
  199. //easy.AnimateManager.getAnimateData("need_to_download_name");
  200. //TODO 切换到第一个主场景
  201. virus.GameData.get_rank(1);
  202. easy.ViewManager.show(virus.HallView, null, false);
  203. }
  204. }