tsbase
Version:
Base class libraries for TypeScript
47 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameLoop = void 0;
var Timer_1 = require("./Timer");
var Observable_1 = require("../../Patterns/Observable/Observable");
var oneSecond = 1000;
var GameLoop = /** @class */ (function () {
function GameLoop() {
this.framesRendered = 0;
this.gameLoopTimer = new Timer_1.Timer();
this.framerateTimer = new Timer_1.Timer();
this.Framerate = new Observable_1.Observable();
this.GameEvents = new Array();
}
GameLoop.prototype.Start = function (framerate) {
this.startGameLoopTimer(framerate);
this.startFramerateTimer();
};
GameLoop.prototype.Stop = function () {
this.gameLoopTimer.Stop();
this.framerateTimer.Stop();
};
GameLoop.prototype.startGameLoopTimer = function (framerate) {
var _this = this;
var interval = oneSecond / framerate;
this.gameLoopTimer.Interval = interval;
this.gameLoopTimer.AutoReset = true;
this.gameLoopTimer.Elapsed = [
function () { return _this.GameEvents.forEach(function (e) { return e.Publish(); }); },
function () { return _this.framesRendered++; }
];
this.gameLoopTimer.Start();
};
GameLoop.prototype.startFramerateTimer = function () {
var _this = this;
this.framerateTimer.Interval = oneSecond;
this.framerateTimer.AutoReset = true;
this.framerateTimer.Elapsed = [
function () { return _this.Framerate.Publish(_this.framesRendered); },
function () { return _this.framesRendered = 0; }
];
this.framerateTimer.Start();
};
return GameLoop;
}());
exports.GameLoop = GameLoop;
//# sourceMappingURL=GameLoop.js.map