///////////////////////////////////////// // // GameScreen // var GameScreen = function(idScreen, funcInit, funcProc, funcEnd, tps){ this.Screen = document.getElementById(idScreen); this.Ctx = this.Screen.getContext('2d'); this.Size = {X: this.Screen.width, Y: this.Screen.height}; this.Entities = []; this.NewEntities = []; this.Running = false; this.FuncInit = funcInit; this.FuncProc = funcProc; this.FuncEnd = funcEnd; this.TPS = tps || 10; this.TickTime = 1000/this.TPS; this.AccTickTime = this.TickTime; this.PreviousTime = 0; var self = this; this.Tick = function(){ while(self.AccTickTime>=self.TickTime){ self.Update(); if(self.FuncProc){ self.FuncProc(self); } self.CleanDead(); self.InsertAdded(); self.AccTickTime -= self.TickTime; } self.Draw(self.AccTickTime/self.TickTime); var timeNow = performance.now(); self.AccTickTime += timeNow - self.PreviousTime; self.PreviousTime = timeNow; if(self.Running){ window.requestAnimationFrame(self.Tick); }else{ if(self.FuncEnd){ self.FuncEnd(self); } } } }; GameScreen.prototype = { // For internal use CleanDead: function(){ var i = this.Entities.length-1; while(i>0){ if(this.Entities[i].GameEntity.Deleted){ this.Entities.splice(i,1); } i--; } }, InsertAdded: function(){ for(var i=0,n=this.NewEntities.length;i