I have this simple line of code:
timeout() {
this.tick();
if (this._running) {
this._timeoutId = window.setTimeout(this._boundTimeout, this._gameSpeed);
}
}
startRunning() {
this._timeoutId = window.setTimeout(this._boundTimeout, this._gameSpeed);
this._running = true;
}
I know that in requestAnimationFrame
, you just need the callback as the argument like so
this._timeoutId = window.requestAnimationFrame(timeout);
But where do I handle this._gameSpeed
for requestAnimationFrame
?
[UPDATE]: I manage to run by using requestAnimationFrame(this._boundTimeout)
, but it ignores the FPS, hence it is almost impossible to catch its movement. In terms of adding this._gameSpeed
, how do I handle it to add to the requestAnimationFrame
?