Thanks for your help, it worked!
It is not flawless, if make a new object it makes like 5 at a time and the change in strokeweight and mouse when you drag is glitchy after about 2 or 3 squares.
for (int i = tegenstanders.size() - 1; i >= 0; i–) {
t[i].update();
t[i].getX();
t[i].getY();
}
this did not work though… without “[i]” it does.
ArrayList<Tegenstander> tegenstanders;
void setup(){
fullScreen();
background(0);
tegenstanders = new ArrayList<Tegenstander>();
tegenstanders.add(new Tegenstander());
}
void draw(){
background(0);
for (int i = tegenstanders.size() - 1; i >= 0; i--) {
Tegenstander t = tegenstanders.get(i);
t.update();
t.getX();
t.getY();
}
println(tegenstanders.size());
if(keyPressed && key == 'v'){
tegenstanders.add(new Tegenstander());
}
}
class Tegenstander{
int x;
int y;
Tegenstander(){
x = 100;
y =100;
}
void update(){
fill(100);
rect(x, y, 100, 100);
if(mouseX> x && mouseX < x+100 && mouseY > y && mouseY < y+100){
cursor(HAND);
stroke(255);
if(mousePressed){
strokeWeight(5);
x = mouseX-50;
y = mouseY-50;
}
else{
strokeWeight(2);
}
}
else{
cursor(ARROW);
noStroke();
}
}
int getX(){
return x;
}
int getY(){
return y;
}
}