sorry if i'm not understanding everything and asking here.
the overCheck() is working, but i get for every object in my class a "false" for the boolean "over", when i press the mouse. i don't understand?
Code:
// the variables
int numBalls = 10;
Ball[] balls = new Ball[numBalls];
boolean over = false;
// setup is doing things one time in the beginning
void setup() {
size(1024, 768);
noStroke();
smooth();
for (int i = 0; i < numBalls; i++) {
balls[i] = new Ball(random(width), random(height), random(20, 40), i, balls);
}
}
// draw is doing things everytime
void draw() {
background(0);
for (int i = 0; i < numBalls; i++) {
// the class methods for every object in my array
balls[i].display();
balls[i].distCheck();
balls[i].overCheck();
}
}
// mousemethods classextern
// mousePressed
void mousePressed() {
for (int i = 0; i < numBalls; i++) {
balls[i].mousePressed(mouseX, mouseY, mouseButton);
}
}
// mouseReleased
void mouseReleased() {
for (int i = 0; i < numBalls; i++) {
balls[i].mouseReleased();
}
}
// creating the class
class Ball {
float x, y;
float diameter;
int id;
Ball[] others;
Ball(float xin, float yin, float din, int idin, Ball[] oin) {
x = xin;
y = yin;
diameter = din;
id = idin;
others = oin;
}
// show all
void display() {
fill(255,125);
rect(x, y, diameter, diameter);
}
// check distance and draw the line
void distCheck() {
for (int i = id + 1; i < numBalls; i++) {
float dx = others[i].x - x;
float dy = others[i].y - y;
float distance = sqrt(dx*dx + dy*dy);
float minDist = 200;
if (distance < minDist) {
stroke(255);
line(x, y, others[i].x, others[i].y);
}
}
}
// check for every ball if mouse is over
void overCheck(){
if(mouseX > x && mouseX < (x+diameter) && mouseY > y && mouseY < (y+diameter)){
over = true;
println("w");
} else {
over = false;
}
}
// Mousemethods class intern
// mousepressed
void mousePressed(int mx, int my, int mbutton){
println(over);
}
// mousereleased
void mouseReleased(){
}
// the End
}