+ 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); } }

28th Jan 2018, 6:43 PM
Harsit Baral
Harsit Baral - avatar
2 Respuestas
0
i think you're declaring shape twice. Maybe it is just shape= new Shape()
3rd Feb 2018, 3:53 PM
Tibi Mose
Tibi Mose - avatar
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.
9th Apr 2019, 10:15 PM
Person
Person - avatar