Created
January 30, 2013 18:23
-
-
Save loktar00/4675433 to your computer and use it in GitHub Desktop.
game loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * jGame.update() | |
| * | |
| * Main update loop for the game, updates all objects, and calls the renderer. | |
| **/ | |
| update : function(){ | |
| var curTime = (new Date()).getTime(), | |
| update = this.update; | |
| this.deltaTime = curTime - this.lastTime; | |
| this.lastTime = curTime; | |
| this.accTime += this.deltaTime; | |
| // Limit the delta queing | |
| if(this.accTime > 60){ | |
| this.accTime = 0; | |
| } | |
| while (this.accTime > this.timeStep) | |
| { | |
| this.accTime -= this.timeStep; | |
| var entities = this.entities, | |
| entLen = this.entities.length; | |
| while(entLen--){ | |
| var object = entities[entLen]; | |
| if(object !== undefined){ | |
| if(object.live){ | |
| object.update(this.timeStep /100); | |
| }else{ | |
| this.removeEntity(object); | |
| } | |
| } | |
| } | |
| } | |
| this.renderer.redraw(); | |
| this.frameRateLabel.text = Math.round(1000/this.deltaTime) + " fps"; | |
| this.currentFrameRate = Math.round(1000/this.deltaTime); | |
| var self = this; | |
| requestAnimFrame( function(){self.update()} ); | |
| //this.intervalId = setTimeout(function(){self.update()}, this.frameRate); | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment