src/App.js
/**
 * A application loop. When created the callback will be called until stop is
 * called.
 *
 * @param {Function} callback the function that should be called by the loop.
 * @param {Object} that changes "this" to the specified when callback is called.
 * @returns {AppLoop}
 */
A application loop. When created the callback will be called until stop is
called.

@param {Function} callback the function that should be called by the loop.
@param {Object} that changes "this" to the specified when callback is called.
A application loop . When created the callback will be called until stop is called . @param { Function } callback the function that should be called by the loop . @param { Object } that changes " this " to the specified when callback is called .
function AppLoop(callback, that) {
	var keepUpdating = true;
	var lastLoopTime = new Date();
	function loop() {
		if (!keepUpdating) return;
		requestAnimFrame(loop);
		var time = new Date();
		var dt = (time - lastLoopTime) / 1000;
		if (dt >= 3) dt = 0.25;
		callback.call(that, dt);
		lastLoopTime = time;
	}
	this.stop = function() {
		keepUpdating = false;
	};
	this.resume = function() {
		keepUpdating = true;
		lastLoopTime = new Date();
		loop();
	};
	loop();
	return this;
}
function AppLoop ( callback , that ) { var keepUpdating = true ; var lastLoopTime = new Date ( ) ; function loop ( ) { if ( ! keepUpdating ) return ; requestAnimFrame ( loop ) ; var time = new Date ( ) ; var dt = ( time - lastLoopTime ) / 1000 ; if ( dt >= 3 ) dt = 0.25 ; callback . call ( that , dt ) ; lastLoopTime = time ; } this . stop = function ( ) { keepUpdating = false ; } ; this . resume = function ( ) { keepUpdating = true ; lastLoopTime = new Date ( ) ; loop ( ) ; } ; loop ( ) ; return this ; }
A application loop.
A application loop .