Can't use 'width' or 'height' within an object?

Hey, I've noticed I get error messages whenever I try to use the keywords 'width' or 'height' inside of an object. For example when I do something like:

var circle = { x: width/2, y: height/2 };

And then use circle.x or .y somewhere, I'll get two error messages saying 'circle' is undefined and 'width' is undefined. But if I just type in values instead using the words 'width' and 'height' it'll work fine. width and height seem to work fine everywhere else, is there a reason they don't work inside of an object? This isn't a major issue, just wondering if that's normal behavior or a bug.

Tagged:

Answers

  • We should postpone both width & height till after createCanvas() is called. :-S
    Pretty much most of p5.js' API doesn't exist until preload() is called back. =;

  • Ah, cool. Thanks!

Sign In or Register to comment.