I'm trying to make a walking animation for automatically moving Camels, consisting in 2 sprites I made. The Object should switch out per act() round, but I have no clue how to do this.
// In your class, as a global variable private boolean firstImage = true;
// Inside of act() firstImage = !firstImage; if(firstImage) setImage(„path/to/image1.png“); else setImage(„path/to/image2.png“);
// Globally private GreenfootImage image1 = new GreenfootImage(„path/to/image1.png“); private GreenfootImage image2 = new GreenfootImage(„path/to/image2.png“); // In act() firstImage = !firstImage; if(firstImage) setImage(image1); else setImage(image2); // Or the last two lines shorter setImage(firstImage ? image1 : image2);
// In your class, as a global variable private boolean firstImage = true;
// Inside of act() firstImage = !firstImage; if(firstImage) setImage(„path/to/image1.png“); else setImage(„path/to/image2.png“);
// Globally private GreenfootImage image1 = new GreenfootImage(„path/to/image1.png“); private GreenfootImage image2 = new GreenfootImage(„path/to/image2.png“); // In act() firstImage = !firstImage; if(firstImage) setImage(image1); else setImage(image2); // Or the last two lines shorter setImage(firstImage ? image1 : image2);