fix: previous scene being rendered twice (#97)

This commit is contained in:
Jacob
2022-12-06 15:16:11 +01:00
committed by GitHub
parent 3d599f4e17
commit 90205bdc1a
4 changed files with 12 additions and 37 deletions

View File

@@ -308,12 +308,12 @@ export class Node implements Promisable<Node> {
public readonly key: string;
public constructor({children, key, ...rest}: NodeProps) {
this.key = use2DView()?.registerNode(this, key) ?? key ?? '';
initialize(this, {defaults: rest});
for (const {signal} of this) {
signal.reset();
}
this.add(children);
this.key = use2DView()?.registerNode(this, key) ?? key ?? '';
}
@computed()

View File

@@ -52,43 +52,11 @@ export class View2D extends Layout {
}
public override render(context: CanvasRenderingContext2D) {
const currentMatrix = this.localToParent();
const customMatrix = context.getTransform();
if (
customMatrix.a !== currentMatrix.a ||
customMatrix.b !== currentMatrix.b ||
customMatrix.c !== currentMatrix.c ||
customMatrix.d !== currentMatrix.d ||
customMatrix.e !== currentMatrix.e ||
customMatrix.f !== currentMatrix.f
) {
this.position
.x(customMatrix.m41)
.position.y(customMatrix.m42)
.scale.x(
Math.sqrt(
customMatrix.m11 * customMatrix.m11 +
customMatrix.m12 * customMatrix.m12,
),
)
.scale.y(
Math.sqrt(
customMatrix.m21 * customMatrix.m21 +
customMatrix.m22 * customMatrix.m22,
),
)
.rotation(Math.atan2(customMatrix.m12, customMatrix.m11));
}
this.computedSize();
this.computedPosition();
super.render(context);
}
protected override transformContext() {
// do nothing
}
protected override requestLayoutUpdate() {
this.updateLayout();
}

View File

@@ -20,8 +20,13 @@ export function addInitializer<T>(target: any, initializer: Initializer<T>) {
export function initialize(target: any, context: any) {
if (target[INITIALIZERS]) {
target[INITIALIZERS].forEach((initializer: Initializer<any>) =>
initializer(target, context),
);
try {
target[INITIALIZERS].forEach((initializer: Initializer<any>) =>
initializer(target, context),
);
} catch (e: any) {
e.inspect ??= target.key;
throw e;
}
}
}

View File

@@ -227,7 +227,9 @@ export class Project {
} else {
this.context.clearRect(0, 0, this.width, this.height);
}
this.context.drawImage(this.previousBuffer.canvas, 0, 0);
if (this.previousScene) {
this.context.drawImage(this.previousBuffer.canvas, 0, 0);
}
this.context.drawImage(this.buffer.canvas, 0, 0);
}