1
I’m having trouble uploading images to the server. I would like to know what is the correct way to pre-load these images.
// JavaScript Functions
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function load(){
var colors = ["http://meusite.com/pasta/img/playerRightC.png","http://meusite.com/pasta/img/playerLeftC.png","http://meusite.com/pasta/img/playerRight.png","http://meusite.com/pasta/img/playerLeft.png","http://meusite.com/pasta/img/wallpaper01.png","http://meusite.com/pasta/img/cheese.png","http://meusite.com/pasta/img/toca.png","http://meusite.com/pasta/img/help1.png","http://meusite.com/pasta/img/help2.png","http://meusite.com/pasta/img/help3.png","http://meusite.com/pasta/img/cnImg.png"];
for (color in colors) {
var img = new Image();
img.src = colors[color];
}
}
load();
sleep(6000).then(() => {
StartGame();
});;
window.addEventListener('keydown', KeyDown, true);
I added a 6000ms delay to start the game, so the images could be loaded by the load function.
However, the images are not preloaded, yet there is a delay from 0.5ms to 2.0s on slower connections trying to play the game. Is this way of loading the images correct? It has a more effective way?
Thanks friend! A doubt, I can load sound from mp3 format this way too?
– Luan pedro
Then I no longer know. I believe that sound works the base if streaming, will be playing as it goes being loaded... but I’m not sure.
– Sam