@fuwu-yuan/bgew
Version:
Baguette Game Engine Web is a french 2D Web game engine
55 lines (54 loc) • 1.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timer = void 0;
class Timer {
constructor(time, end, remove = () => { }) {
this._counter = 0;
this._time = 0;
this._repeat = true;
this._loop = 0;
this._time = time;
this._cb = end;
this._remove = remove;
}
update(delta) {
this._counter += delta;
if (this._counter >= this._time) {
this._cb();
this._counter = 0;
this._loop++;
if (!this._repeat) {
this._remove();
}
}
}
get counter() {
return this._counter;
}
set counter(value) {
this._counter = value;
}
get time() {
return this._time;
}
set time(value) {
this._time = value;
}
get repeat() {
return this._repeat;
}
set repeat(value) {
this._repeat = value;
}
get loop() {
return this._loop;
}
set loop(value) {
this._loop = value;
}
stop() {
this.repeat = false;
this._remove();
}
}
exports.Timer = Timer;