We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Issues with Timing
Page Index Toggle Pages: 1
Issues with Timing (Read 272 times)
Issues with Timing
Feb 24th, 2009, 10:14am
 
I'm having some issues with my sketch.  I'm essentially making a slideshow of images, along with captions that change with each image.  However, the problem I'm having is that both the pictures and captions advnace at variable rates that I would determine, and the captions don't necessarily advance at the same time as the pictures.

My idea was to create methods for the captions and the methods, and have a parameter be for when it needs to happen, hopefully by specifying the elapsed millisecends that need to have occured before the method executes.

I've tried code that I'd seen in other examples using timers, and I've even tried putting in while loops that do nothing until the specified number of milliseconds pass, but this only works the first time. I've been poking around this site and my Processing book, and through these forums, but I'm at a loss at this point.

Any ideas about what I'm doing wrong/completely missing?

Hope I've made the issue clear, and thanks in advance!
Re: Issues with Timing
Reply #1 - Feb 25th, 2009, 4:34pm
 
I like doing timing things by elapsed frames (by comparing them against the constantly-incrementing frameCount variable). So for variable amounts of elapsed timing, I might make an array of at what frame index an image or caption should appear on the screen.
(untested code)

PImage[] images;
String[] captions;
int[] imageStartFrame;//imageStartFrame[x]=which frame images[x] should show up at
int[] captionStartFrame;
int currentImageIndex=0;
int currentCaptionIndex=0;

draw(){
  background(0);
  if(imageStartFrame[currentImageIndex]==frameCount){    
       currentImageIndex++;
  }
if(captionStartFrame[currentCaptionIndex]==frameCount){    
       currentCaptionIndex++;
  }
  image(images[currentImageIndex],0,0,320,240,320,240);
  showCaption(captions[currentCaptionIndex);//your own method
}
Page Index Toggle Pages: 1