Skip to content

Commit

Permalink
fix: Issue with interpolation with parallax
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jan 6, 2024
1 parent b536e0a commit e8daee8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/engine/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Graphics/GraphicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class GraphicsSystem extends System<TransformComponent | GraphicsComponen
// https://doc.mapeditor.org/en/latest/manual/layers/#parallax-scrolling-factor
// cameraPos * (1 - parallaxFactor)
const oneMinusFactor = Vector.One.sub(parallax.parallaxFactor);
const parallaxOffset = this._camera.pos.scale(oneMinusFactor);
const parallaxOffset = this._camera.drawPos.scale(oneMinusFactor);
this._graphicsContext.translate(parallaxOffset.x, parallaxOffset.y);
}

Expand Down

0 comments on commit e8daee8

Please sign in to comment.