I am not finished yet
First of all thanks to the feedback from some. It gave me a bit more motivation to work more on this project.
Somebody bothered the loading timer after each round and guess what i also didn’t like that. So I fixed it. The cause was that each time a ghost was placed onto the canvas a new HTML image tag would have to be created, source set to the ghost image URL and than the script had to wait for the browser to load the image and only afterward it could place it onto the canvas. I fixed that by loading each image at the start of website loading. This way I already have all images loaded and only need to print them to the canvas no waiting needed.
There was also this major randomness error. If you remember from an older post I did some random generator thing which makes it impossible to spawn too few ghosts while still allowing random positions on a mask without too much hugging each other.
What i did not notice back then because of the mask, that if the mask isn’t applied the ghosts form a straight line from top left to bottom right. And guess what the error was:
if (delta(g.x, x) < ghostSize / 2 || delta(g.y, y) < ghostSize / 2) vs if (delta(g.x, x) < ghostSize / 2 && delta(g.y, y) < ghostSize / 2).
I used and OR instead of and AND logic operator. It took me 30 mins to figure out :(
Another person mentioned they had a optimization warning in their console. I did not had such a warning because I use Firefox personally. I also test on chromium but i don’t look into logs there, how ever now i did. The Dev tools of chromium really improved a lot, but i am still going to use Firefox as main browser.
Well, I fixed all warnings chromium gave me.
The context of a HTML canvas has an optimization flag in case you request data from it frequent what i do. I just had do set this option to true.
Also the drawing part of the ghosts is now not blocking the main thread entirely with timeout calling the same function which acts like a for loop to distribute work over time. Otherwise the website would freeze for a second because printing images to a canvas is very sloww for some reason I don’t want to get into now.
For the loading part i threw a bit CSS and HTML together making up a progress bar and added some random phrases so users don’t get bored.
Furthermore instead of creating new HTML tags each scene change the code now already has them in the HTML code loaded but changes their visibility. In theory this should improve performance because the browser doesn’t have to create new elements each time.