From e8daee85b06e14c24b4db4e7c250446a50be8d4b Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Fri, 5 Jan 2024 19:56:01 -0600 Subject: [PATCH] fix: Issue with interpolation with parallax --- src/engine/Camera.ts | 9 +++++---- src/engine/Graphics/GraphicsSystem.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/engine/Camera.ts b/src/engine/Camera.ts index d8a9a1b1c..14f50757f 100644 --- a/src/engine/Camera.ts +++ b/src/engine/Camera.ts @@ -317,9 +317,9 @@ export class Camera implements CanUpdate, CanInitialize { /** * Interpolated camera position if more draws are running than updates * - * Enabled when `Engine.fixedUpdateFps` is enabled + * Enabled when `Engine.fixedUpdateFps` is enabled, in all other cases this will be the same as pos */ - public interpolatedPos: Vector = this.pos.clone(); + public drawPos: Vector = this.pos.clone(); private _oldPos = this.pos.clone(); @@ -626,6 +626,7 @@ export class Camera implements CanUpdate, CanInitialize { if (!this._posChanged) { this.pos = center; } + this.pos.clone(this.drawPos); // First frame bootstrap // Ensure camera tx is correct @@ -781,7 +782,7 @@ export class Camera implements CanUpdate, CanInitialize { */ public draw(ctx: ExcaliburGraphicsContext): void { // default to the current position - this.pos.clone(this.interpolatedPos); + this.pos.clone(this.drawPos); // interpolation if fixed update is on // must happen on the draw, because more draws are potentially happening than updates @@ -790,7 +791,7 @@ export class Camera implements CanUpdate, CanInitialize { const interpolatedPos = this.pos.scale(blend).add( this._oldPos.scale(1.0 - blend) ); - interpolatedPos.clone(this.interpolatedPos); + interpolatedPos.clone(this.drawPos); this.updateTransform(interpolatedPos); } diff --git a/src/engine/Graphics/GraphicsSystem.ts b/src/engine/Graphics/GraphicsSystem.ts index 361bbf017..187dce74e 100644 --- a/src/engine/Graphics/GraphicsSystem.ts +++ b/src/engine/Graphics/GraphicsSystem.ts @@ -112,7 +112,7 @@ export class GraphicsSystem extends System