8000 canvas willreadfequently optimization · sjefvanleeuwen/shooter@8ecdf28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ecdf28

Browse files
canvas willreadfequently optimization
1 parent 773382a commit 8ecdf28

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

js/imageBackgroundScroller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class ImageBackgroundScroller {
4040
this.tempCanvas = document.createElement('canvas');
4141
this.tempCanvas.width = 20;
4242
this.tempCanvas.height = 20;
43-
// Cache the 2D context once
44-
this.tempCtx = this.tempCanvas.getContext('2d');
43+
// Use willReadFrequently to improve getImageData performance.
44+
this.tempCtx = this.tempCanvas.getContext('2d', { willReadFrequently: true });
4545

4646
this.lastColorSample = { x: null, y: null, color: null, time: 0 };
4747
}

0 commit comments

Comments
 (0)
0