Jump to content
  • Advertisement
Sign in to follow this  
gandolf1212

Quick, how do I animation Java?

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Not like good animation, just 32 stuff. More specifically, how do I keep recalling the graphics function? Is there some way I can get rid of the flicker or does that require the java equilivent of directx? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
To eliminate the flicker, use double buffering. I think Java finally has built-in ways to do double buffering, but I don't trust them yet. Your best bet is to do it yourself- create an offscreen image, draw everything to the image, then draw the image to the screen. Sample code

To "keep recalling the graphics function", make your own thread (which I usually include in the main class), like this:


class YourMainClass
....
....
....
class TickThread extends Thread
{
public void run()
{
boolean bAlive = true;

while (bAlive)
{
repaint();
try
{
sleep(10);
} catch (InterruptedException e) {}
}
}
}


and start it like this:


TickThread myThread = new TickThread();
myThread.run();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!