Newbie question - how to stop moving object?
in
Programming Questions
•
2 years ago
Hi there,
I am completely new to Processing, so more than grateful for any advice to achieve the following:
- making a moving object stop when hovering over it
- and open a new object when clicking on it
Below is the beginning of the code (i.e.. if I go for example with the mouse over 'A', 'A' should stop; if I then click on 'A', it should open or link to sth; the same for 'B', 'C' and 'D' etc.)...
Thanks so much for any help with this or any hint in the right direction!
-------------
class Writing {
float x;
float y;
int radius;
float speed = 0.5;
int direction = 1;
Writing (float tempX, float tempY, int tempRadius) {
x = tempX;
y = tempY;
radius = tempRadius;
}
void move1 () {
x += speed * direction;
if ((x > width - radius-520) || (x < radius + 110 && direction < 0)) {
direction = - direction;
}
}
void move2 () {
x += speed * direction;
if ((x > width - radius-340) || (x < radius + 430 && direction < 0)) {
direction = - direction;
}
}
void move3 () {
x += speed * direction;
if ((x > width - radius-340) || (x < radius + 430 && direction < 0)) {
direction = - direction;
}
}
void move4 () {
x += speed * direction;
if ((x > width - radius-120) || (x < radius + 600 && direction < 0)) {
direction = - direction;
}
}
void display1() {
fill(56,120,160);
text ("A",x-10,y+2);
}
void display2() {
fill(56,120,160);
text ("B",x-10,y+2);
}
void display3() {
fill(56,120,160);
text ("C",x-10,y+2);
}
void display4() {
fill(56,120,160);
text ("D",x-10,y+2);
}
}
Writing work1;
Writing work2;
Writing work3;
Writing work4;
void setup () {
size (900,600);
background(225);
smooth();
work1 = new Writing (150, 430, 15);
work2 = new Writing (450, 410, 15);
work3 = new Writing (450, 380, 15);
work4 = new Writing (600, 350, 15);
}
void draw() {
background(255);
work1.move1();
work1.display1();
work2.move2();
work2.display2();
work3.move3();
work3.display3();
work4.move4();
work4.display4();
}
1