There are two issues with this code.
First the getImage() code that was supplied for the course had to be remarked out before the pheromone image would display.
The second issue is in the updateImage() we calculate the size of the Pheromone and the Transparency level. When the code executes the pheromone simply blinks and disappears instead of shrinking and fading. Any suggestions will be appreciated.
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Color; /** * Pheromones are dropped by ants when they want to communicate something to * other ants. * * @author Michael Kolling * @version 1.1 */ public class Pheromone extends Actor { public GreenfootImage image; public static final int IMAGE_SIZE = 30; private final static int MAX_INTENSITY = 180; private static final int MAX_TRANSPARENCY = 255; private int intensity; private int currentSize; private int currentTransparency; /** * Create a new drop of pheromone with full intensity. */ public Pheromone() { intensity = MAX_INTENSITY; updateImage(); } /** * The pheromone decreases the intensity. When the intensity reaches zero, it disappears. */ public void act() { fade(); updateImage(); } /** * Decrease the intensity of the pheromone and * remove it if the intensity is zero */ public void fade() { // Decrease the intensity of the Pheromone by 1 intensity -= 1; // If its intensity is less than or equal to 0, remove it from AntWorld if (intensity <= 0) { getWorld().removeObject(this); } } /** * Update the size and transparency of the pheromone */ public void updateImage() { GreenfootImage image = new GreenfootImage(IMAGE_SIZE,IMAGE_SIZE); currentSize = IMAGE_SIZE * (intensity/MAX_INTENSITY); currentTransparency = MAX_TRANSPARENCY * (intensity/MAX_INTENSITY); // Make the image white. Use the constant java.awt.Color.WHITE image.setColor(new Color(255,255,255, currentTransparency)); // Create a circle of right size to represent the Pheromone image.fillOval(0, 0, currentSize, currentSize); setImage(image); } /** * Return the image object */ //public GreenfootImage getImage() //{ //return image; //} }