aspose file tools*
The moose likes Java in General and the fly likes Animating independent objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Animating independent objects?" Watch "Animating independent objects?" New topic
Author

Animating independent objects?

Anthony Yulo
Ranch Hand

Joined: Feb 22, 2003
Posts: 52
I'm trying to make an animation involving 3 or more circle shapes...
The Circle shapes are encapsulated in a class...
so i'm trying to animate them, move them in any direction, randomly..
I think the way to do this is using threads of course.. and i think to do this i need the encapsulating class to implement runnable?
and have a Thread object as its member data?
Instantiate three objects and then run them all at once...
and then have the graphics context or the background area as a critical section? ryt?
is this the way to do this? any suggestions?
tnx a lot..


it's alright, the gun isn't loaded... - hey
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
You could use threads, or you could use a single controller program that implements a timer. Each object would register a timer handler with the controller. Each objects timer handler would then call it's objects move method.
Tom Blough


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Anthony Yulo
Ranch Hand

Joined: Feb 22, 2003
Posts: 52
Thanks for the repply man..
But i jst thought that the sprites or the circles must be running on independent threads...
BUt anyway, could u help me on this..
So i have the main threads running the animation loop and drawing and the sprite threads...

in the sprite thread...

and then in the main thread...
[CODE]
void run{
while(true)
{
//increment timer()
//notify sprite threads of timer increment so they can udpate position
//wait until all sprite threads have updated their positions
//draw the sprite locations
delay(timerdelay);
}
}
So thats what i want to do..HOw do i implement this?
Where do i put the synchronized keyword?
DO i use Object.notifyAll() and Object.wait()?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think this was posted to multiple forumzes. Did you get a good answer in the other? I'd try combining the bits of logic you had into one the shape itself:

Any of that sound useful?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Anthony Yulo
Ranch Hand

Joined: Feb 22, 2003
Posts: 52
Yes.. i've posted this in another thread.. just though it would be better if i started a new thread for this topic.. neways,
If i used your suggested code, i need all the shapes synchronized so that for each increment of the timer all the shapes should have moved by only one position..
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Yes, if you want them all to move at exactly the same instant. With the timing inside the shape as I suggested, you COULD have each one refreshing at a different rate or at different times. That might be a good thing or a bad thing depending on your requirements.
If I wanted to use one clock, I'd move the timing into the driver class:

A number of sprites might look smoother if they are allowed to randomize their intervals or fall out of perfect sync. That might be fun just to try and see how it looks to the eye.
Let us know how this works out!
 
Don't get me started about those stupid light bulbs.
 
subject: Animating independent objects?