Hey there,
If i understand your problem correctly, you will need a variable in your blob class that tracks whether or not the sound playing is the first time. Then a series of checks to replay the the sounds manually at the point of refresh. I've edited your class Blob slightly:
- class Blob { //DEFINE CLASS
- float x, y;
- float big;
- boolean on;
- boolean firstPlayThrough = false;//variable to check if song has played through the first time
- int num;
- float sp;
- float sp1;
- float sp2;
- Blob( float xTemp, float yTemp, float bigTemp, boolean onTemp,
- int numTemp, float splashTemp, float splash1Temp, float splash2Temp) { //CONSTRUCTOR
- x = xTemp; //makes variables able to function in coding
- y = yTemp;
- big = bigTemp;
- on = onTemp;
- num = numTemp;
- println(num);
- sp = splashTemp;
- sp1 = splash1Temp;
- sp2 = splash2Temp;
- }
- void trigger(int xTemp, int yTemp) {
- this.on = true;
- this.x = xTemp;
- this.y = yTemp;
- println(this);
- if(firstPlayThrough == false){
- a[num].play();//play through the song once if you havent before
- }
-
- }
- void update() { //CLASS FUNCTIONALITY / METHODS
- if (this.on ==true) {
- frameRate (35);
- smooth();
- pushMatrix();
- translate(x, y); //use of variable
- //check if the song is done playing.
- if(a[num].isPlaying() == false){
//pause and rewind the song to the start regardless of which play it is.
- a[num].pause();
- a[num].rewind();
- // if this is the first play through...
- if(firstPlayThrough == false) firstPlayThrough = true;//this will make it so the first play through only happens once
- }
- if (big > 70) {
- big = 0;
- if(firstPlayThrough == true){
- //only react to the refresh if the sound is done playing throught first time
- a[num].pause();//pause the current playback wherever it is
- a[num].cue(0);//set it at the start
- a[num].play();//play
- }
- }
- big +=1;
- fill(sp, sp1, sp2, 180);
- stroke( 250, 60 );
- ellipse(0, 0, big, big);
- popMatrix();
- }
- fill(90, 90, 90);
- rect (10, 460, 50, 30);
- if (mouseX> 9 && mouseX< 61 && mouseY> 459 && mouseY<491) {
- fill (130, 130, 130);
- rect (10, 460, 50, 30);
- if (mousePressed) {
- fill (200, 200, 200);
- rect (10, 460, 50, 30);
- this.on = false; // only hides circles. DOES NOT reset count
- }
- }
- }
- }
- void stop() {
- //song.stop();
- minim.stop();
- super.stop();
- }
So what I did:
I added the boolean firstPlayThrough initially false so when you the trigger function runs it plays that song in a[num].
In your update function every frame, we are checking if the sound is done playing. If it is then we pause and rewind the song to the beginning then check to see if the first play through boolean is still false, meaning thats the first time the sound has been played. If it is still false, turn it to true so that boolean doesnt run again.
Inside your conditional checking for the value of big, I add a check to see if the firstPlayThrough boolean is true, aka the sound has played through at least once. If so, then regardless of where the sound is, we pause it, cue it back to the start and play it again, forcing a replay at that point.
I think that will work for what you mean. dont quote me on this syntax but i think its all correct.
Hope this helps.
Kobby