Skip to content

Commit

Permalink
Fix visual glitches when loading joystick images
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Dec 13, 2024
1 parent 77377c4 commit cd2a909
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/shared/renderers/JoysticksRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ export default class JoysticksRenderer implements TabRenderer {
private WHITE_COLOR = "#eeeeee";

private lastRenderState = "";
private imageLoadCount = 0;

constructor(root: HTMLElement) {
this.CANVAS = root.getElementsByTagName("canvas")[0] as HTMLCanvasElement;
for (let i = 0; i < 6; i++) {
let image = document.createElement("img");
this.IMAGES.push(image);
image.addEventListener("load", () => {
this.imageLoadCount++;
});
}
}

Expand All @@ -38,7 +42,14 @@ export default class JoysticksRenderer implements TabRenderer {
let isLight = !window.matchMedia("(prefers-color-scheme: dark)").matches;

// Exit if render state unchanged
let renderState: any[] = [canvasWidth, canvasHeight, isLight, window.devicePixelRatio, command];
let renderState: any[] = [
canvasWidth,
canvasHeight,
isLight,
window.devicePixelRatio,
command,
this.imageLoadCount
];
let renderStateString = JSON.stringify(renderState);
if (renderStateString === this.lastRenderState) {
return;
Expand Down

0 comments on commit cd2a909

Please sign in to comment.