We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I created an array, and I am trying to load all my images using a for loop.
My images are named in order for that, but when I reload the page to see my sketch, the console show a message saying that the path of my images could not be found.
Here is an image of my images, and the path
https://i.imgur.com/aVlqKfu.png
Here is the message of the console
https://i.imgur.com/4woK730.png
And here is my code. Can anyone tell me what is wrong, Ive been thinking for a while and I cant figure it out.. Thanks
let campeones = [];
let imgCampeones = [];
function preload() {
for(var i = 0; i < 6; i++){
imgCampeones[i]= loadImage(`C:/Users/DDV2 NVE/Desktop/CC/campeon${i}.jpg`);
}
}
function setup() {
createCanvas(700, 600);
for(var i = 0; i < 10; i++){
let x = random(width);
let y = random(height);
let campeon = random(imgCampeones);
campeones[i] = new Campeones(x, y, 50, campeon);
}
}
function draw() {
background(200);
for(let champ of campeones){
champ.drawCampeon();
champ.move();
}
}
class Campeones {
constructor(x, y , r, campeon){
this.x = x;
this.y = y;
this.r = r;
this.campeon = campeon;
}
drawCampeon(){
image(this.campeon, this.x, this.y, this.r, this.r);
}
move(){
this.x += random(-5, 5);
this.y += random(-5, 5);
}
Clicked(px, py){
if(px > this.x && px < this.x + this.r && py > this.y && py < this.y + this.r){
return true
}
}
intersection(enemy){
let d = dist(this.x, this.y, enemy.x, enemy.y);
return (d < this.r + enemy.r)
}
}
Answers
I made it !!
Thank you so much.
I´ll take your advices about the class issues ;D
Can you share your solution?
Kf
Are those back ticks rather than single quotes?
https://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Koogs, yes !
Kfrajer, I moved the folder inside my project, as GoToLoop suggested.
https://image.ibb.co/gDn6Ax/Captura.png
The double jpg was my fault, I named the images with .jpg