Add clearCanvas flag to RuntimeScene for multi-scene rendering support (#5525)

* Add `clearCanvas` field to `RuntimeScene` class and pass it to `PIXI.Renderer.render` as `clear` option to support multi-scene rendering.

* Show in developer changelog
This commit is contained in:
Gleb Volkov
2023-08-31 10:10:15 +02:00
committed by GitHub
parent f07e3bfe19
commit 40639f5578
2 changed files with 25 additions and 3 deletions
@@ -119,7 +119,7 @@ namespace gdjs {
// Render the background color.
pixiRenderer.backgroundColor = this._runtimeScene.getBackgroundColor();
pixiRenderer.backgroundAlpha = 1;
pixiRenderer.clear();
if (this._runtimeScene.getClearCanvas()) pixiRenderer.clear();
isFirstRender = false;
}
@@ -192,7 +192,7 @@ namespace gdjs {
this._runtimeScene.getBackgroundColor()
);
threeRenderer.resetState();
threeRenderer.clear();
if (this._runtimeScene.getClearCanvas()) threeRenderer.clear();
threeScene.background = new THREE.Color(
this._runtimeScene.getBackgroundColor()
);
@@ -251,7 +251,9 @@ namespace gdjs {
// Render all the layers then.
// TODO: replace by a loop like in 3D?
pixiRenderer.backgroundColor = this._runtimeScene.getBackgroundColor();
pixiRenderer.render(this._pixiContainer);
pixiRenderer.render(this._pixiContainer, {
clear: this._runtimeScene.getClearCanvas(),
});
this._layerRenderingMetrics.rendered2DLayersCount++;
}
+20
View File
@@ -32,6 +32,10 @@ namespace gdjs {
_requestedChange: SceneChangeRequest;
/** Black background by default. */
_backgroundColor: integer = 0;
/** Should the canvas be cleared before this scene rendering. */
_clearCanvas: boolean = true;
_onceTriggers: OnceTriggers;
_profiler: gdjs.Profiler | null = null;
@@ -524,6 +528,22 @@ namespace gdjs {
return this._backgroundColor;
}
/**
* Set whether the canvas should be cleared before this scene rendering.
* This is experimental: if possible, try to avoid relying on this and use
* custom objects to build complex scenes.
*/
setClearCanvas(shouldClearCanvas: boolean): void {
this._clearCanvas = shouldClearCanvas;
}
/**
* Get whether the canvas should be cleared before this scene rendering.
*/
getClearCanvas(): boolean {
return this._clearCanvas;
}
/**
* Get the name of the scene.
*/