I am teaching a coding class and trying to load and display images on the p5js website as a part of an assignment. I keep running into an error: failed to load error.
p5.js says: It looks like there was a problem loading your image. Try checking if the file path (https://assets.editor.p5js.org/646bea83ae1b050019dbb6ff/384b84a1-0432-40a0-ad85-de2dd87c6568.png) is correct, hosting the file online, or running a local server.
I have the file uploaded into the sketch, and it is showing up in my assets in the account, but the error persists. Am I missing a step here?
my code:
let img
function preload(){
img = loadImage("bart1.png")
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
image(img,0,0)
}
I just tried it with img = createImg("bart1.png") and that ended up working on this one, so i might have a workaround. I am curious if there is something with loadImage() that I am missing or is a bit askew.
thanks for testing that, it seems hit or miss. some of the students in my class were able to do it, and some were not. Same basic code, a different outcome.
I ran your code in the Processing IDE with p5.js mode and it also ran without error; image was placed in the sketch folder. I can’t explain why it works sometimes and others not.