That is a less than ideal solution though. Not only are you creating a completely new image each time you check, but you also have to compare the images pixel by pixel to see if they are equal.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.util.ArrayList; static ArrayList<GreenfootImage> images = new ArrayList<GreenfootImage>(); private int frame; static public void initialize() { images.add( new GreenfootImage( "image 1 name" )); images.add( new GreenfootImage( "image 2 name" )); ... } public void act() { frame ++; if (frame >= images.size()) { frame = 0 ; } setImage(images.get(frame)); } |
1 | (Classname).initialize(); |