+ 1
Confused in p5.js
Can somebody please tell me why the following code won't work?(Yes, In the HTML file I made sure to use the p5.js library) var shape; function setup() { createCanvas(600,400); var shape = new Shape(); } function draw() { background(11); shape.show(); } function Shape() { this.x = 50; this.y = 50; this.show = function() { rect(this.x,this.y,10,10); fill(255,255,0); } }
2 Antworten
0
i think you're declaring shape twice. Maybe it is just shape= new Shape()
0
You declared shape twice. In the setup function, you need to get rid of var. It’s just “shape = new Shape();”. You use var outside setup to declare it, than you set it in setup to allow the shape object to access p5.js certain p5.js tools.