
-----------------------------------
Harblkipz
Tue May 13, 2008 8:45 am

Help with sprite animation
-----------------------------------
Hey, so I have a set of images, and I have loaded them into an array of images in my program. I then have a JFrame created, and my plan is to display the images in a repeating cycle as an ImageIcon of JLabel. When I load one image on its own, it displays correctly in the frame, but when I try to cycle through the array in a For loop, the images are not being cycled in the window... No idea why. Any help is appreciated.

My Main class:

import javax.swing.*;
public class Game{
   public static void main(String[] args){
       boolean loop = true;
       Koopa koopa = new Koopa();
       JFrame frame = new JFrame("Mario Game"); 
       JLabel turtle = new JLabel(new ImageIcon(koopa.trtl(1))); 
       frame.add(turtle); 
       frame.setSize(200,200);
       frame.validate(); 
       frame.setVisible(true); 
       frame.setLayout(null); 
       while(loop==true){
           for(int i = 0;i < 5; i++){
               turtle = new JLabel(new ImageIcon(koopa.trtl(i))); 
               frame.validate(); 
           }
       }
   }
} 


And here is the class I use to load the turtle images:

import java.awt.*;
public class Koopa{
public Image trtl(int G) { 
    Image[] trtl = new Image[5];
    for(int i= 0 ;i