C
C
CrystaZZ2019-08-12 17:51:22
JavaScript
CrystaZZ, 2019-08-12 17:51:22

How to fix Failed to load resource: net::ERR_FILE_NOT_FOUND 11[object%20Object]:1 error?

the code:
5d517ce55bd35472021594.png

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');


const fon = new Image();
fon.src = "img/fon.jpg"

let image = new Image();

image.onload = draw;


let khight = [
  'img/1.png', 
  'img/2.png', 
  'img/3.png', 
  'img/4.png', 
  'img/5.png',
  'img/6.png', 
  'img/7.png', 
  'img/8.png', 
  'img/9.png', 
  'img/10.png',
  'img/11.png', 
  'img/12.png', 
  'img/13.png', 
  'img/14.png', 
  'img/15.png'   
]

khight[0] = {x : 0, y : 0};
let speed = 50;

function key(e){
    if(e.keyCode == 32){
        khight[0].x+=15;
    }
}

let x = 0;

window.addEventListener("keydown", key)

let time_curent = 0;

setInterval(() => {
    time_curent = (time_curent + 1) % khight.length
    image.src = khight[time_curent];
}, speed);


function draw() {
  ctx.drawImage(fon, 0, 0);
  
  for(let i = 0; i < khight.length; i++){
  ctx.drawImage(image, khight[i].x, khight[i].y, 198, 185);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-08-12
@CrystaZZ

let khight = [
  'img/1.png', 
  'img/2.png', 
  'img/3.png', 
  'img/4.png', 
  'img/5.png',
  'img/6.png', 
  'img/7.png', 
  'img/8.png', 
  'img/9.png', 
  'img/10.png',
  'img/11.png', 
  'img/12.png', 
  'img/13.png', 
  'img/14.png', 
  'img/15.png'   
]

khight[0] = {x : 0, y : 0};

and what did you mean by that? first you declare an array of strings, then you make the first element an object, and it ends up in image.src

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question