Animation Threading

In writing a program that runs through a series of images, I instansiate an Animator object and call start() at the appropriate time (which runs a thread to continuously call the display method of my GLEventListener [that is: my JFrame]). When through displaying this series of images, I call my animator’s stop() method.

The problem lies in that the stop() method kills the current rendering thread, which then traverses the stack to kill all the other threads. At that point, the program goes into a deadlock and I have no control of the monitor state.
I first attempted just leaving the animator’s thread as the new main thread, but after all the images are through there is a constant, repeated EOF exception.
I tried setting my animator to null, but its thread kept on calling the display() method regardless (a complete waste).

Is there some way to go back to my original (AWTEvent-0) main thread that simply has wait() and notify() [for all intents and purposes]?

I use javax.swing.JFrame and net.java.games.jogl.Animator
Also, both my original main and the animator’s thread have priority=6…if that helps

(It would be nice if i could get rid of that animator’s thread altogether, without destroying all the others.)

Dont use threads for stuff like that.

You really don’t need em anyways. Just tell all sprites to tick() each frame, which in turn picks the next animation frame which should be displayed (at the next render() call).

Since you’re using Swing anyway, how about using a Timer to generate events and repaint periodically? That will be done from the Event Dispatch Thread, while the technical Timer stuff is handled from its own Thread invisible to the user.

If I am using Swing, I either do one of two things for animation:

  1. If in FSEM (full screen), then I create a new Animator thread that upates the screen and then sleeps for 30 milliseconds. I can tell it to pause if I need to, but more or less it continually runs in the background.
  2. When in windowed mode, I make a Timer and pass that 30 and a new ActionListener that fires every time the timer updates. Inside the actionPerformed method I have both my game logic updates and a call to my paintComponent(g) method, which overrides the JPanel’s usual paintComponent.

And as for displaying a series of animations: each item on the screen has its own variable for what animation it’s on, and an array of images. Then every timestep it simply calls animations[index % animations.length] and adds to the index every timestep. No threads needed.