Game Career Guide Forums

Game Career Guide Forums (http://www.gamecareerguide.com/forums/index.php)
-   Programming (http://www.gamecareerguide.com/forums/forumdisplay.php?f=7)
-   -   Animation in Java applets (http://www.gamecareerguide.com/forums/showthread.php?t=5482)

julianak 10-28-2011 12:54 AM

Animation in Java applets
 
Basic animation techniques

Many forms of animation are possible in Java. What all of them have in common is that they create some kind of motion on the screen by drawing successive frames at a relatively high speed (usually about 10-20 times per second).

We will start by creating a simple template applet for doing animations and slowly elaborate it until we arrive at a fairly complete applet.

Using a thread


To update the screen multiple times per second, you need to create a new Java thread that contains an animation loop. The animation loop is responsible for keeping track of the current frame and for requesting periodic screen updates. To implement a thread, you must either create a subclass of Thread or adhere to the Runnable interface.

A common mistake is to put the animation loop in the paint() method of an applet. Doing so will have strange side effects because it holds up the main AWT thread, which is in charge of all drawing and event handling.

As an example I have written a small template applet, called Example1Applet, that illustrates the general outline of an animation applet. Example1Applet shows how to create a thread and call the repaint() method at fixed intervals. The number of frames per second is specified by passing in an applet parameter. Here is an example of what you would put in your HTML document:

<applet code=Example1Applet.class width=200 height=200>
<param name=fps value=20>
</applet>

Protector one 10-31-2011 11:45 AM

Re: Animation in Java applets
 
what is this i don't even

Jane 01-26-2012 06:28 AM

Re: Animation in Java applets
 
Thanks for the info, I am very interested in learning how to do java animation!


All times are GMT -8. The time now is 05:02 AM.

Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.