42_ft_transcendence/frontend/static/js/api/game/Time.js

40 lines
647 B
JavaScript

class Time
{
constructor()
{
/**
* @type {Number}
*/
this._last_frame = undefined;
/**
* @type {Number}
*/
this._current_frame = undefined;
}
deltaTime()
{
return (this._current_frame - this._last_frame) !== NaN ? this._current_frame - this._last_frame : 0;
}
deltaTimeSecond()
{
return this.deltaTime() / 1000;
}
get_fps()
{
return 1 / this.deltaTimeSecond();
}
new_frame()
{
this._last_frame = this._current_frame;
this._current_frame = Date.now();
}
}
export { Time }