First of all thanks for your reply, I know what I have to do now.
I understand what you are telling me and I know this would help me a lot, but I dont know how to do what you are telling me.
You wrote this line inside the class but it confuses me.
what does this line inside the class do? Also how do I call it in the main code?
Tegenstander(){
}
After trying what you suggested I got an error when I typed this line in processing because “someName” isn’t an array.
int a = someName[n].getX();
How do I fix that error or did I miss something in my code?
my maincode looks like this now:
ArrayList<Tegenstander> tegenstanders;
Tegenstander someName = new Tegenstander();
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());
}
And like you said I made a void update and the getX function in my class. You wrote:
float x;
int getX(){
return x;
}
Is that possible? shouldn’t they be either a float or an int?
class Tegenstander{
int x;
int y;
Tegenstander(){
}
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;
}
}