We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Ideally mouseDragged would start a time, and mouseReleased would stop the timer. The number of seconds from the timer would be used to determine the speed of a variable for the LeftEye and Right Eye classes. I've been trying different things with this for awhile now and I keep hitting a wall. Any help is appreciated, thank you.
PImage Face;
PImage Outline;
LeftEye [] LE = new LeftEye[1];
RightEye[] RE = new RightEye[1];
//Timer [] time = new Timer [1];
float tempySpeed;
boolean eyeRoll = false;
void setup() {
size (500, 650);
Face = loadImage("Face.png");
Outline = loadImage("Outline.png");
for (int i = 0; i < LE.length; i++) {
LE[i] = new LeftEye();
}
for (int i = 0; i < RE.length; i++) {
RE[i] = new RightEye();
}
}
void mouseClicked() {
if (mouseButton == LEFT) {
eyeRoll = true;
} else {
eyeRoll = false;
}
}
void draw() {
for (int i = 0; i<LE.length; i ++) {
LE[i].display();
if (eyeRoll == true) {
LE[i].bounce();
}
}
for (int i = 0; i<RE.length; i++) {
RE[i].display();
if (eyeRoll== true) {
RE[i].bounce();
}
}
Face.resize(400, 650);
image(Face, 50, 0);
Outline.resize(400, 650);
image(Outline, 50, 0);
}
PImage LeftEye;
class LeftEye {
float ySpeed;
float yPos;
float Time;
float getTime() {
return(Time);
}
Timer [] time = new Timer [1];
LeftEye() {
ySpeed = 10;
yPos = -122;
}
void mouseDragged() {
for (int i = 0; i < time.length; i++) {
time[i] = new Timer();
//for (int i = 0; i<time.length; i++) {
time[i].setTime(1);
}
for (int i = 0; i<time.length; i++) {
time[i].countUp();
}
}
void mouseReleased() {
for (int i = 0; i<time.length; i++) {
time[i].duration();
Time = ySpeed;
}
}
void display() {
LeftEye = loadImage("Eye.png");
LeftEye.resize(390, 568);
image(LeftEye, -17, yPos);
//image(LeftEye,-17,mouseY-120);
}
void bounce() {
yPos = yPos+ySpeed;
if (yPos >=255 || yPos<= -122) {
yPos = -122;
}
}
}
PImage RightEye;
class RightEye {
float ySpeed;
float yPos;
float Time;
float getTime() {
return(Time);
}
Timer [] time = new Timer [1];
RightEye() {
ySpeed = 7;
yPos = -122;
}
void display() {
for (int i = 0; i < time.length; i++) {
time[i] = new Timer();
}
RightEye = loadImage("Eye.png");
RightEye.resize(390, 568);
image(RightEye, 139, yPos);
//image(RightEye,139,mouseY-120);
}
void mouseDragged() {
for (int i = 0; i<time.length; i++) {
time[i].setTime(1);
}
for (int i = 0; i<time.length; i++) {
time[i].countUp();
}
}
void mouseReleased() {
for (int i = 0; i<time.length; i++) {
time[i].duration();
Time = ySpeed;
}
}
void bounce() {
yPos = yPos+ySpeed;
if (yPos >=255 || yPos<= -122) {
yPos=-122;
}
}
}
class Timer {
float Time;
float getTime() {
return(Time);
}
void setTime (float set) {
Time = set;
}
void countUp() {
Time += frameRate*60;
}
void duration() {
getTime();
}
}
Answers
Edit post, highlight code, press Ctrl-o to format
And take the bold off your text please. We can hear you well enough.
@koogs Thanks, and sorry! Bold was unintentional.
Lots of great timer examples in the forum:
See also Timing Utilities and Countdown Timer under "Utilities" on the libraries page -- looking at examples can be helpful.