Files
2018-12-03 17:31:53 +08:00

1 line
5.4 KiB
JavaScript

var AppView=function(e){function t(){e.call(this),this.name_arr=["item_0","item_1","item_2","item_3","item_4","item_5","item_6","item_7"],this.r=60,this.input=new egret.TextField,this.initMainContainer(),this.createTxtField(),this.initBitmapChilds(Number(this.input.text)),this.addEventListener(egret.Event.ENTER_FRAME,this.enterFrameHandler,this)}__extends(t,e);var i=(__define,t),r=i.prototype;return r.createTxtField=function(){this.addChild(this.input),this.input.width=480,this.input.height=60,this.input.x=0,this.input.border=!0,this.input.borderColor=16777215,this.input.verticalAlign=egret.VerticalAlign.MIDDLE,this.input.type=egret.TextFieldType.INPUT,this.input.text="10",this.input.addEventListener(egret.Event.CHANGE,this.numChangeHandler,this)},r.initMainContainer=function(){this.mainContainer=new egret.Sprite,this.addChildAt(this.mainContainer,0),this.drawTexture=new egret.RenderTexture,this.stageBmp=new egret.Bitmap,this.stageBmp.bitmapData=this.stageBmd,this.mainContainer.addChild(this.stageBmp),this.mainContainer.touchEnabled=!1},r.numChangeHandler=function(e){this.initBitmapChilds(Number(this.input.text))},r.initBitmapChilds=function(e){this.removeBitmapChild(),this.arr_child=[];for(var t=0;e>t;t++){var i=new VBitmapMovie;i.createMc(this.name_arr[Math.floor(Math.random()*this.name_arr.length)]),i.vx=8*Math.random()-4,i.vy=8*Math.random()-4,i.x=Math.random()*this.width,i.y=Math.random()*this.height,this.arr_child.push(i),i.play()}},r.removeBitmapChild=function(){if(this.arr_child){for(var e=this.arr_child.length,t=0;e>t;t++){var i=this.arr_child[t];i.recycle()}i=null}},r.enterFrameHandler=function(e){if(this.arr_child){for(var t=this.width-this.r,i=this.height-this.r,r=0,n=this.arr_child.length,s=(new egret.Rectangle(0,0,100,100),new egret.Sprite);n>r;){var a=this.arr_child[r],o=Math.floor(a.x)+a.vx,h=Math.floor(a.y)+a.vy;a.play(),0>o?(o=0,a.vx=-a.vx):o>t&&(o=t,a.vx=-a.vx),0>h?(h=0,a.vy=-a.vy):h>i&&(h=i,a.vy=-a.vy),a.x=o,a.y=h,r++,s.addChild(a.getCurrentBitmapFrameInfo())}this.drawTexture.drawToTexture(s,new egret.Rectangle(0,0,this.width,this.height),1),this.stageBmp.texture=this.drawTexture,s.removeChildren(),s=null}},t}(egret.DisplayObjectContainer);egret.registerClass(AppView,"AppView");var LoadingUI=function(e){function t(){e.call(this),this.createView()}__extends(t,e);var i=(__define,t),r=i.prototype;return r.createView=function(){this.textField=new egret.TextField,this.addChild(this.textField),this.textField.y=300,this.textField.width=480,this.textField.height=100,this.textField.textAlign="center"},r.setProgress=function(e,t){this.textField.text="Loading..."+e+"/"+t},t}(egret.Sprite);egret.registerClass(LoadingUI,"LoadingUI");var Main=function(e){function t(){e.call(this),this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this)}__extends(t,e);var i=(__define,t),r=i.prototype;return r.onAddToStage=function(e){this.loadingView=new LoadingUI,this.stage.addChild(this.loadingView),RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE,this.onConfigComplete,this),RES.loadConfig("resource/default.res.json","resource/")},r.onConfigComplete=function(e){RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE,this.onConfigComplete,this),RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onResourceLoadComplete,this),RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onResourceLoadError,this),RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS,this.onResourceProgress,this),RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR,this.onItemLoadError,this),RES.loadGroup("preload")},r.onResourceLoadComplete=function(e){"preload"==e.groupName&&(this.stage.removeChild(this.loadingView),RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onResourceLoadComplete,this),RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onResourceLoadError,this),RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS,this.onResourceProgress,this),RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR,this.onItemLoadError,this),this.createGameScene())},r.onItemLoadError=function(e){console.warn("Url:"+e.resItem.url+" has failed to load")},r.onResourceLoadError=function(e){console.warn("Group:"+e.groupName+" has failed to load"),this.onResourceLoadComplete(e)},r.onResourceProgress=function(e){"preload"==e.groupName&&this.loadingView.setProgress(e.itemsLoaded,e.itemsTotal)},r.createGameScene=function(){this._appView=new AppView,this._appView.x=0,this._appView.y=0,this.addChild(this._appView),this.checkSize()},r.checkSize=function(){this._appView&&(this._appView.width=this.stage.stageWidth,this._appView.height=this.stage.stageHeight)},t}(egret.DisplayObjectContainer);egret.registerClass(Main,"Main");var VBitmapMovie=function(e){function t(){e.call(this),this._currentFram=1}__extends(t,e);var i=(__define,t),r=i.prototype;return r.createMc=function(e){this.recycle();var t=RES.getRes(e+"_json"),i=RES.getRes(e+"_png"),r=new egret.MovieClipDataFactory(t,i);this._movieClipData=r.generateMovieClipData(e),this._mc=new egret.MovieClip(this._movieClipData)},r.play=function(){this._currentFram++,this._currentFram>this._movieClipData.numFrames&&(this._currentFram=1)},r.getCurrentBitmapFrameInfo=function(){return this._mc.x=this.x,this._mc.y=this.y,this._mc.gotoAndStop(this._currentFram),this._mc},r.recycle=function(){this._mc&&this._mc.parent&&this._mc.parent.removeChild(this._mc),this._movieClipData=null},t}(egret.Sprite);egret.registerClass(VBitmapMovie,"VBitmapMovie");