| 200 | public isStopped(): boolean { return this._state === 'Stopped' } |
| 201 | |
| 202 | public start(): void { |
| 203 | if (this.isRunning()) { return } |
| 204 | if ((!this.isRunning()) && (this.time >= this._duration)) { return } |
| 205 | this._setState('Running') |
| 206 | this._lasttime = this._ticker.now() |
| 207 | this._ticker.start(() => { |
| 208 | const now = this._ticker.now() |
| 209 | const delta = (now - this._lasttime) * this._timescale |
| 210 | if ((this._time + delta) > this._duration) { |
| 211 | this._time = this._duration |
| 212 | this.stop() |
| 213 | } else { |
| 214 | this._time += delta |
| 215 | } |
| 216 | this._lasttime = now |
| 217 | this._onTickCb(this._time) |
| 218 | }) |
| 219 | } |
| 220 | public pause(): void { |
| 221 | this._ticker.stop() |
| 222 | this._setState('Paused') |