oop mouse trigger
in
Programming Questions
•
1 year ago
Im having issues trying to make the animation start in my code. I can establish a global variable with a boolean and void mousePressed trigger but I plan on being able to activate multiples of these animation on one screen and need to make it local. I have been beating my brain against the wall (Almost literally) I have some pieces but can't put make them function together. Any tips?
Here are my pieces of code. The first section is a key trigger i plan to us with a class C used as a counter for the amount of animations on screen.
- void mousePressed() {
t[c].trigger(mouseX,mouseY);
c++;
}
Here is the rest of the trigger code
- void trigger(int xTemp, int yTemp) {
this.on = true;
this.x = xTemp;
this.y = yTemp;
println(this);
audio[num].play();
audio[num].loop();
}
And here is my animation code
- Blob[] b;
- void setup() {
- b = new Blob[1];
- for ( int i=0; i < b.length; i ++ ) {
- b[i] = new Blob( random(width), random(height),
- random(-1, 1));
- }
- }
- void draw() {
- fill( 0, 16 ); // black out last frame
- rect(0, 0, width, height);
- for ( int i=0; i < b.length; i ++ ) {
- b[i].update();
- }
- }
- class Blob {
- float x, y;
- float big;
- Blob( float xTemp, float yTemp, float bigTemp) {
- x = xTemp;
- y = yTemp;
- big = bigTemp;
- }
- void update() {
- frameRate (20);
- smooth();
- pushMatrix();
- translate(x, y);
- if (big > 30) {
- big = 0;
- }
- big +=1;
- fill(50, 120, 170, 50);
- stroke( 250, 60 );
- ellipse(0, 0, big, big);
- popMatrix();
- }
- }
I've been struggling how to put these together. Just looking for tips/hints as to which way to approach this.
2