Hi, I am somewhat of an intro coder for p5.js. Anyways, I am working on some code that changes a drawFunction I made on an index of images and I keep getting:
"Uncaught TypeError: Cannot read property ‘width’ of undefined
^ As Above. But that makes no sense to me considering that there is not width at drawInstructions or at draw? Does anyone have any idea why it would this is showing? I cannot get past my initial splash page in my drawFunction. Here is the code that might be related to the error. If you need more context, please let me know.
Any help will be great! Thanks!
function setup() {
createCanvas(1280, 720);
// Center our drawing objects
imageMode(CENTER);
textAlign(CENTER);
textSize(24);
makecontinueButton1();
// set to one for startup
drawFunction = drawSplash;
}
// Very simple, sets the background color and calls your state machine function
function draw() {
// will call your state machine function
drawFunction();
}
/************SPLASH + INTROS ********************/
//Splash Page
drawSplash = function() {
image(images[0], 640, 360);
continueButton1.draw();
}
//Instruction Page
drawInstructions = function() {
image(image[19], 640, 360);
}
/**************** Buttons ***********************/
function makecontinueButton1() {
continueButton1 = new Clickable;
continueButton1.setImage(continueimg);
continueButton1.color = "#00000000";
continueButton1.width = continueimg.width;
continueButton1.height = continueimg.height;
continueButton1.locate(1144, 655);
}
continueButton1Pressed = function () {
if (drawFunction === drawSplash) {
drawFunction = drawInstructions;
}
}