Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Animation Threading  (Read 3106 times)
0 Members and 1 Guest are viewing this topic.
Offline revolutions

Innocent Bystander

« Posted 2005-07-20 19:34:51 »

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
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.)
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2005-07-20 20:20:27 »

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).

弾幕 ☆ @mahonnaiseblog
Offline Ask_Hjorth_Larsen

Junior Devvie

Java games rock!

« Reply #2 - Posted 2005-07-20 20:57:59 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #3 - Posted 2005-08-12 17:42:29 »

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.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!