Skip to content

Commit

Permalink
Clear last rendered frame
Browse files Browse the repository at this point in the history
  • Loading branch information
erikhaandrikman committed Apr 21, 2023
1 parent 06a33db commit 43498e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/destroy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@


document.addEventListener("keydown", (e) => {
// spacebar
if (e.keyCode === 32) {
if (app) {
app.destroy();
Expand Down
18 changes: 14 additions & 4 deletions src/tree/Stage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class Stage extends EventEmitter {

try {
return !!window.WebGLRenderingContext;
} catch(e) {
} catch (e) {
return false;
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export default class Stage extends EventEmitter {
opt('memoryPressure', 24e6);
opt('bufferMemory', 2e6);
opt('textRenderIssueMargin', 0);
opt('fontSharp',{precision:0.6666666667, fontSize: 24})
opt('fontSharp', { precision: 0.6666666667, fontSize: 24 })
opt('clearColor', [0, 0, 0, 0]);
opt('defaultFontFace', 'sans-serif');
opt('fixedDt', 0);
Expand Down Expand Up @@ -224,6 +224,16 @@ export default class Stage extends EventEmitter {
this.textureManager.destroy();
this._renderer.destroy();

// clear last rendered frame
if (this.gl) {
this.gl.clearColor(0.0, 0.0, 0.0, 0.0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
} else if (this.c2d) {
this.c2d.clearRect(
0, 0, this.c2d.canvas.width, this.c2d.canvas.height
);
}

this.gl = null;
this.c2d = null;
this.ctx = null;
Expand Down Expand Up @@ -510,10 +520,10 @@ export default class Stage extends EventEmitter {
}
}

getChildrenByPosition(x, y){
getChildrenByPosition(x, y) {
const children = [];
this.root.core.update();
this.root.core.collectAtCoord(x,y,children);
this.root.core.collectAtCoord(x, y, children);

return children;
}
Expand Down

0 comments on commit 43498e7

Please sign in to comment.