|
||||||||||||||
. . . . Elena Tresh Foundation Florida . |
Java For Kids Tutorial 7
| Intro |
Begin |
if/else |
Loops |
Arrays |
Graphics |
Animation |
Mouse |
Game |
Real |
Methods |
Class |
Class 2 |
Applet |
MouseClick |
Thread |
Button |
Java Animation
In a for loop draw an object with moving x or y coordinates.
void main()
{
setColor(red);
for(int count = 0 ; count < 50; count++)
{
fillCircle(150, count*5, 50);
delay(0.1);
clearDrawing();
}
}
Try it without clearDrawing() by commenting out that line. e.g. //clearDrawing(); Notes on Above Java Code
Frames Per Second (fps) in Java AnimationsAlso change the delay time. delay stops the program executing for the time that it put between the brackets ( ) after the word delay. The time is give as a double and not an int. That allows us to use fractions of a second as a time delay. If a time delay of 0.10 seconds is given, then the animation's frame rate is 10 frames per second. Video(PAL) goes at 25 frames per second. USA TV runs at 30 fps(frames per second). Japanese anime usually runs at about 4 or 5 frames per second. The more frames per second an animation is given, the smoother
the animation will look. So try the delay in the above animation at 0.5 seconds( delay(0.50); )
and see what it looks like. Is it jerkier or smoother than delay(0.1) ? Try delay(0.025). Another way of doing it
void main() {
int y = 0; // initialise y
int howFar = getDrawingHeight();
setColor(green); // green ball
while(y < howFar )
{
// draw circle
fillCircle(150, y, 50);
// add 5 pixels each time it loops
y = y + 5;
delay(0.1);
clearDrawing();
}
}
to be continued.. . |
|
||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||