Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda