Reputation: 21
I'm using the p5 library for my code, and it seems to break when I try to create a class function using a library function. I went on the reference page, and even the example class functions there use library functions, so I know I'm the one doing something wrong, but I can't seem to figure out what.
Here's my code:
class Enemy {
constructor(x, y, radius, health) {
this.x = x
this.y = y
this.health = health
this.r = radius
this.show();
}
// this breaks on strokeWeight();
show() {
strokeWeight(4);
stroke(255, 0, 0);
noFill();
ellipse(this.x, this.y, this.r * 2, this.r * 2;
}
}
This is the error I get:
Uncaught ReferenceError: strokeWeight is not defined (sketch: line 11)
It says that each function is not defined when I try to comment out strokeWeight();
, stroke();
, noFill();
, or ellipse();
. If you can help, please do. Thanks.
Upvotes: 1
Views: 454
Reputation: 21
I figured it out. I need to put the class after setup()
but before the initialization of objects in the class.
Upvotes: 1