42_ft_transcendence/frontend/static/js/api/game/Time.js
2024-03-31 10:59:39 +02:00

42 lines
660 B
JavaScript

class Time
{
constructor()
{
/**
* @type {Number}
*/
this._last_frame = undefined;
/**
* @type {Number}
*/
this._current_frame = undefined;
}
deltaTime()
{
if (this._last_frame === undefined)
return 0;
return (this._current_frame - this._last_frame);
}
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 };