Slick Loading Animate GIF Image

This section I'll show you how to load Animate GIF. If you load an animate " gif " image as the way you load a " png " image, the image will load perfectly,
however, soon you will realize that the image is not animating. One of the way to load that "
animate image " is use an image edit software to save each of the
images of the animate gif image. I personally use " GIMP ", it's a free open source software which you can obtain from here. Once, you have all the images saved,
lets look at the code.

Example



Click to Download Example

Here, we will use the Animation method.

Animation ani = new Animation();

We create a series of null image objects to hold all the images

//Creates a series of image objects
Image earth1 = null;
Image earth2= null;
Image earth3 = null;
Image earth4 = null;
Image earth5 = null;
Image earth6 = null;
Image earth7 = null;
Image earth8 = null;
Image earth9 = null;
Image earth10 = null;


(You can always store all the images into an array)

We will load all the images the same way as we did from the previous section on "
Loading png Image."

earth1 = new Image("slickloadgifimage/images/10.gif");
earth2 = new Image("slickloadgifimage/images/9.gif");
earth3 = new Image("slickloadgifimage/images/8.gif");
earth4 = new Image("slickloadgifimage/images/7.gif");
earth5 = new Image("slickloadgifimage/images/6.gif");
earth6 = new Image("slickloadgifimage/images/5.gif");
earth7 = new Image("slickloadgifimage/images/4.gif");
earth8 = new Image("slickloadgifimage/images/3.gif");
earth9 = new Image("slickloadgifimage/images/2.gif");
earth10 = new Image("slickloadgifimage/images/1.gif");


Then, we add all the images into an animation frame

ani.addFrame(earth1, 500);
ani.addFrame(earth2, 500);
ani.addFrame(earth3, 500);
ani.addFrame(earth4, 500);
ani.addFrame(earth5, 500);
ani.addFrame(earth6, 500);
ani.addFrame(earth7, 500);
ani.addFrame(earth8, 500);
ani.addFrame(earth9, 500);
ani.addFrame(earth10, 500);


Finally, we will render the animation into the screen in the " render method "

ani.draw(50, 50);

It's a long process with a lot of works, but it's a perfectly working method to load animate gif.


 

  <Slick><Home>