33 lines
546 B
JavaScript
33 lines
546 B
JavaScript
|
|
|
|
class Time
|
|
{
|
|
constructor()
|
|
{
|
|
this._last_frame = undefined;
|
|
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 } |