mirror of
https://github.com/4ian/GDevelop.git
synced 2026-10-12 02:01:17 +00:00
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:
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user