Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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 2006 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 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.)
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!