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 › timing, multiple threads, and events/exceptions
Page Index Toggle Pages: 1
timing, multiple threads, and events/exceptions (Read 288 times)
timing, multiple threads, and events/exceptions
Oct 23rd, 2008, 10:46pm
 
Hello,

I'm new to Java and I'm having a hell of a time trying to figure out how to do what I need to do.  Here's the situation:

I have an animation, and I have a fade between each image in the animation.  The animation framerate is variable (for sync to midi clock, tap tempo, whatever), and the fade start time is variable (if the fade is 50%, animation is at 400ms per frame, then fade starts at 200ms for a duration of 200ms).

So I want to have one thread that will Thread.sleep( frameRateInMs ) and another thread that will Thread.sleep( fadePercent * frameRateInMs ).  And at the end of each respective threads sleep, it should fire off an event, which will be caught by my main draw().... and if draw() catches a nextFrame Event it will go to the next frame, and if it catches a startFade Event it will start out a fade in the frame buffer.

So, er, how do I do this?  I've figure out how to get the threads working, but all they're doing right now is println() when they awake from their deep threaded sleep.  How can I get the threads to throw exceptions or events that are then caught?  Which do I use?  And how do I catch them?

Thanks all of you lovely people/cyborgs.
Re: timing, multiple threads, and events/exception
Reply #1 - Oct 23rd, 2008, 10:56pm
 
I should also state, in case anyone suggests doing rid of the threads... I do need to be able to modify the animations even as they are playing - think play and record being on simultaneously.  Hence my inhability to just do this all with delay()s.
Page Index Toggle Pages: 1