Update changed to array of buttons

This commit is contained in:
Lev
2021-04-17 19:00:07 -05:00
parent 8ba3b819ee
commit fda9a75922

View File

@ -4,22 +4,30 @@ let locY = 200;
let w = 200; let w = 200;
let h = 100; let h = 100;
let myButton = null; let myButton = null;
let buttonArray = [];
function setup() { function setup() {
createCanvas(900, 600); createCanvas(900, 600);
myButton = new Button(200, 200, 200, 100); buttonArray.push(new Button(200, 200, 200, 100));
buttonArray.push(new Button(300, 300, 200, 100));
} }
function draw() function draw()
{ {
background(220); background(220);
myButton.draw(); for(let i=0; i<buttonArray.length; i++)
{
buttonArray[i].draw();
}
} }
function mousePressed() function mousePressed()
{ {
myButton.flick(mouseX, mouseY); for(let i=0; i<buttonArray.length; i++)
{
buttonArray[i].flick(mouseX, mouseY);
}
} }
class Button class Button