Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] Choppy animation

This topic is 5394 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

I was wondering if java animation has to be choppy if you are not using bindings to some grapichs library? For some reason the following code gives a fairly smooth animation, but sometimes it stops and the animation gets choppy. This code is placed inside a class that inherits from JPanel and is invoked every 40 ms by a javax.swing.Timer. public void paintComponent( Graphics g ){ super.paintComponent( g ); Graphics2D gBuffer=(Graphics2D) g; gBuffer.drawLine( 0, 25, 392, 25 ); gBuffer.drawLine( 0, 250, 392, 250 ); gBuffer.drawString( "Score: "+score, 150, 20 ); gBuffer.fillRect( ball.getXpos1(), ball.getYpos1(), ball.size(), ball.size() ); gBuffer.fillRect( paddOne.getXpos1(), paddOne.getYpos1(), paddOne.getDepth(), paddOne.getWidth() ); gBuffer.fillRect( paddTwo.getXpos1(), paddTwo.getYpos1(), paddTwo.getDepth(), paddTwo.getWidth() ); } Are there any way to make this paint code faster or is my computer just not fast enough? By the way I am using a P3 800 MHz with 128 Mb RAM.

Share this post

Link to post
Share on other sites
Don''t invoke the animation code with the Timer. It can be prempted by other events in the event dispatch thread.

Create a custom thread to do all your main loop work like moving and painting. This way it will run as fast as your computer can.

First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post

Link to post
Share on other sites

  • 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!