carregandoImagem.js 469 B

123456789101112131415161718192021222324252627
  1. // carregando imagens - HTMLImageElement
  2. function loadImages() {
  3. imagesUrl.forEach((url) => {
  4. let img = new Image(); //HTMLImageElement
  5. img.onload = () => {
  6. images.push(img);
  7. }
  8. img.src = url;
  9. });
  10. }
  11. function drawImages() {
  12. let i = 0;
  13. images.forEach((img) => {
  14. let context = canvas.getContext("2d");
  15. context.drawImage(img, i, 0);
  16. i += 300;
  17. });
  18. }
  19. let images = [];
  20. let imagesUrl = [
  21. "img/garage.png",
  22. "img/house.png",
  23. ];