Files
GDevelop/GDJS/Runtime/timer.ts
T
Florian Rival 2c4fa1d1c2 Switch the game engine documentation to TypeDoc (#3593)
* This adds link between types, a more readable rendering, a better search and, more generally, makes the [game engine documentation](https://docs.gdevelop-app.com/GDJS%20Runtime%20Documentation/index.html) much easier to browse.
2022-02-03 13:58:44 +01:00

79 lines
1.6 KiB
TypeScript

/*
* GDevelop JS Platform
* Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
namespace gdjs {
/**
* Represents a timer, which must be updated manually with {@link gdjs.Timer.updateTime}.
*/
export class Timer {
_name: string;
_time: float = 0;
_paused: boolean = false;
/**
* @param name The name of the timer.
*/
constructor(name: string) {
this._name = name;
}
/**
* Get the name of the timer
* @return The name of the timer
*/
getName(): string {
return this._name;
}
/**
* Get the time of the timer, in milliseconds.
* @return The time of the timer, in milliseconds.
*/
getTime(): float {
return this._time;
}
/**
* Notify the timer that some time has passed.
* @param time The elapsed time, in milliseconds.
*/
updateTime(time: float): void {
if (!this._paused) {
this._time += time;
}
}
/**
* Change the time.
* @param time The new time, in milliseconds.
*/
setTime(time: float): void {
this._time = time;
}
/**
* Reset the time to zero.
*/
reset(): void {
this.setTime(0);
}
/**
* Set if the timer is paused.
* @param enable true to pause the timer, false otherwise.
*/
setPaused(enable: boolean): void {
this._paused = enable;
}
/**
* Check if the timer is paused.
*/
isPaused(): boolean {
return this._paused;
}
}
}