fix animation ugliness in turn-based mode

Uguhughugh it looks SO SMOOTH NOW. I can go to bed happy.
This commit is contained in:
Timothy Stiles 2020-09-26 23:45:53 +10:00
parent e908434a20
commit ccfd5c30ce
2 changed files with 11 additions and 3 deletions

View File

@ -787,8 +787,9 @@ class Player extends PrimaryView {
this._advance_handle = null;
return;
}
this.last_advance = performance.now();
if (this.state === 'playing') {
this.advance_by(1);
}
@ -806,6 +807,13 @@ class Player extends PrimaryView {
this.update_ui();
}
}
if (this.level.waiting_for_input)
{
//freeze tic_offset in time so we don't try to interpolate to the next frame too soon
this.tic_offset = 0;
}
let dt = 1000 / TICS_PER_SECOND;
if (this.state === 'rewinding') {
// Rewind faster than normal time
@ -822,7 +830,7 @@ class Player extends PrimaryView {
// TODO i'm not sure it'll be right when rewinding either
// TODO or if the game's speed changes. wow!
if (this.level.waiting_for_input) {
this.last_advance = performance.now();
//freeze tic_offset in time
}
else
{

View File

@ -58,7 +58,7 @@ export class CanvasRenderer {
return;
}
let tic = (this.level.tic_counter ?? 0) + tic_offset;
let tic = (this.level.tic_counter ?? 0) + tic_offset + (this.level.waiting_for_input ? 1 : 0);
let tw = this.tileset.size_x;
let th = this.tileset.size_y;
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);