It looks like a cool game. I think I have figured out what is going on… First of all, the mazeOff function will just draw a new maze off the screen, but the maze on the screen is not moved because it is a set of rectangles and not a sprite, so drawing the new maze off the screen is probably not doing what you want it to do and it really doesn’t need to be done.
What IS happening, though is that your winner function is designed to display the winner screen when appropriate, but if the winning conditions aren’t met, the maze is drawn (mazeOn). So, when you lose, it’s not winning, so the maze is drawn, again and again.
When you do lose, you unhide the loser screen, but after it’s drawn, the winner clause still kicks in and the maze is drawn on top. The solution is to add a “drawSprites” block inside the loser clause, so the sprites are drawn with the loser sprite on top
Hopefully this makes sense. The order of drawing inside the draw loop can get a little confusing and does definitely make a difference.
In regards @mwood has provided a decent solution to your original problem, however, might i suggest just combining the win and loss functions together?
logically speaking looking at something like that is somewhat disorienting, and separating conditions which all end in the same result (player can no longer play) by doing this you can easily see why you have this problem
Below is some suggestion code for improvement you can do what you like with it
function gameover() {
if(score >= 20) {
B.setAnimation("winner");
} else if (dig.isTouching(pac)) {
pac.destroy();
dig.destroy();
loser.visible = true;
} else if (!loser.visible){
mazeOn();
}
}
also with this method I’ve made your mazeOff function completely redundant as it was not needed in the first place hope this helps!