Skip to content

Commit

Permalink
Do not replace frame if already there
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiro committed Nov 20, 2023
1 parent 2558831 commit 858408f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ function renderPlayer(key) {
}
} else {
const nextFrame = `./${key}/${frame + 1}.png`;
game.$[key].$image.src = nextFrame;
if (game.$[key].$image.dataset.src !== nextFrame) {
game.$[key].$image.dataset.src = nextFrame;
game.$[key].$image.src = nextFrame;
}

game.$[key].$progress.firstChild.textContent = `${Math.floor(z)}m`;
}
Expand Down Expand Up @@ -238,6 +241,7 @@ function preloadImages(key) {
frames.push("lost.gif");
frames.forEach((i) => {
const img = new Image();
const src = `./${key}/${i}`;
img.onload = () => {
loaded++;
if (loaded === frames.length) {
Expand All @@ -250,7 +254,7 @@ function preloadImages(key) {
resolve();
}
};
img.src = `./${key}/${i}`;
img.src = src;
});
});
}
Expand Down

0 comments on commit 858408f

Please sign in to comment.