File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Animating independent objects?

 
Anthony Yulo
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Tom Blough
Ranch Hand
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anthony Yulo
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anthony Yulo
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic