-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Here is an example of usage where this problem will occur.
Please note the value and usage of the this.replay_speed variable as the delay argument in the Phaser.Timer.loop() method (and since it internally uses the Phaser.Timer.create() method, it is also affected):
My code (breaks Phaser.Timer.loop()):
// Song play speed ( (90 / 193) * 1000 = 466.321243523 )
this.replay_speed = (song_replay.meta.duration_sec / song_replay.track_1.length) * 1000;
// Song play timer according to song play speed
this.song_replay_timer = this.game.time.create(false);
this.song_replay_timer.loop(this.replay_speed, this.replaySongData, this);
this.song_replay_timer.start();
Here since this.replay_speed ends up being a float, when the Phaser.Timer.update() method sets the value to .tick it can't seem to parse the float as a timestamp and returns a value that will make it so the Timer stops looping.
Timer.update() (http://docs.phaser.io/Timer.js.html#sunlight-1-line-428)
if (this.events[this._i].loop === true)
{
this.events[this._i].tick = this._newTick;
this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
}
Here this._newTick; ressembles something like this 1234567.5 and the ".5" seems to mess up the condition where the loop checks if the delay time has ellapsed or not:
Timer.update() (http://docs.phaser.io/Timer.js.html#sunlight-1-line-414)
if (this.running && this._now >= this.nextTick && this._len > 0)
Here this._now >= this.nextTick will always return false and the Timer will stop looping. I was able to correct this behaviour by doing a Math.round() of my this.replay_speed variable before setting is as the delay of the Timer.
My corrected code:
// Song play speed ( Math.round((90 / 193) * 1000 = 466.321243523) = 466 )
this.replay_speed = Math.round((song_replay.meta.duration_sec / song_replay.track_1.length) * 1000);
// Song play timer according to song play speed
this.song_replay_timer = this.game.time.create(false);
this.song_replay_timer.loop(this.replay_speed, this.replaySongData, this);
this.song_replay_timer.start();
Perhaps the Phaser.Timer.create() function should Math.round the delay argument so that this never occurs. Thoughts/Opinions ?