Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
DiscordJS/Canvas - Setting src on Canvas.Image() not working

I'm trying to preload a number of images, prior to drawing them using Canvas. I've googled, and read and managed to find some code (with revisions) to cycle through a list of URLs. However, I can't seem to be able to set the housing_image.src to a URL within the list.

Using console.log I can see that the URL is reporting correctly, but when I assign it to the hosuing_image.src the console.log appears blank.

Hopefully it is something super simple that I am missing...

const imageURL = ["https://syrathos.net/other/sale_sign.png","https://syrathos.net/other/housing_1.png"];
    const images = [];
    var imageCount = 0;

function allLoaded(){
    context.drawImage(images[1],0,0);
    context.drawImage(images[0],0,0);
}

for (const URL of imageURL) {
     const housing_image = new Canvas.Image();    
     housing_image.onload = ()=>{ 
        console.log("loaded : " + housing_image.src)
         imageCount += 1;
         if(imageCount === imageURL.length){
             allLoaded();
         }
     }
     console.log(URL)
     housing_image.src = URL;
     images.push(housing_image);
     console.log(housing_image.src);

};

Console Log

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda