Can't draw in while loop.

edited November 2017 in Library Questions

I cant get this playhead to animate in a while loop.

The sounds I want it to play are randomly selected from an array and I want to draw a line to show how far one is from ending each time it's triggered. I need the animation to work in the loop since I'm using that to pause the timers that control my samples.

Here's the relevant section of code.

 while(Ads[i].isPlaying()){
        countDown();
}

void countDown(){
        // draw a line to show where in the song playback is currently located
        strokeWeight(10);
  int posx = int(map(Ads[i].position(), 0, Ads[i].length(), 0, width));
  stroke(0,200,0);
  line(posx, 0, posx, height);
}

I can use

println(( Ads[i].length() - Ads[i].position()) /1000 );

to show the remaining time a sample has on the console but I can't draw that number or represent it in my sketch for some reason.

Tagged:

Answers

  • Your sketch only shows you what you drew inside draw() when draw() is finished. So drawing things inside a while() loop is sort of pointless.

    Consider changing your "while" to an "if".

Sign In or Register to comment.