Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

Smooth Animation

Thread view: 
epbk2 - 14 Jan 2004 15:24 GMT
Hi guys,
Im trying to make a gif image move smoothly across the screen but am having
no luck as the closest I have got is for the image to make many small
movements but this does not look very good.
If anyone has any ideas it would be greatly appreciated.

Many thanks

Ed

ps I have tried using for and while loops and also the Thread.sleep()
command but still with no luck.
Karsten Lentzsch - 14 Jan 2004 15:55 GMT
> Im trying to make a gif image move smoothly across the screen but am having
> no luck as the closest I have got is for the image to make many small
> movements but this does not look very good.
> If anyone has any ideas it would be greatly appreciated.

Check out the Java2D rendering capabilities and
its ability to move, scale and anti-alias stuff.
As a result the rendering result of the individual
steps should look smooth.

Many animations are frame-based, where you increase
the pixel position (or subpixel position) for
every new step. The movement speed then depends
on the rendering engine and the machine state.
For example some garbage collection algorithms
pause for a quite long time.

An alternative is to use a time-based animation.
I provide a free open source animation library
for time-based animations. It ships with a tutorial
application that does something similar to the
Metamorphosis intro, see
http://www.jgoodies.com/freeware/metamorphosis/
http://animations.dev.java.net/

Hope this helps,
Karsten
Saint Ult - 14 Jan 2004 16:03 GMT
> Im trying to make a gif image move smoothly across the screen but am having
> no luck as the closest I have got is for the image to make many small
> movements but this does not look very good.
> If anyone has any ideas it would be greatly appreciated.
Use double buffering maybe.
Linus Norton - 15 Jan 2004 19:55 GMT
double buffering is the way to go.
Igor Buzatovic - 14 Jan 2004 16:06 GMT
> Hi guys,
> Im trying to make a gif image move smoothly across the screen but am
[quoted text clipped - 8 lines]
> ps I have tried using for and while loops and also the Thread.sleep()
> command but still with no luck.

use double buffering technique to avoid flickering, adjust sleep intervals
to aprox. 30 miliseconds, and move image only few pixels in each frame.

sample code:

Graphics offscreen;
Image offImage;
Image myGif;

public void run()
{
   offImage=createImage(300,300);
   offscreen=offImage.getGraphics();
   int x=0;
   int y=0;
   while(running)
   {
       offscreen.drawImage(myGif,x,y,this);
       repaint();
       x++;
       y++;
       try{Thread.sleep(30);}catch(Exception e){}
   }
}

public void paint(Graphics g)
{
   g.drawImage(offImage,0,0,this);
}

public void update(Graphics g)
{
   paint(g);
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.