This site requires JavaScript, please enable it in your browser!
Greenfoot back
JasonZhu
JasonZhu wrote ...

2013/11/6

Problem with Disipation

JasonZhu JasonZhu

2013/11/6

#
{
    private GreenfootImage image;
    private int transparency = 180;
    private int x = 30;
    private int y = 30;

    public Pheromones()
    {
        updateImage();
    }
    
    private void updateImage()
    {
        GreenfootImage img = new GreenfootImage(30,30);
        for (int h=0 ; h<transparency ; h++)
        {
            img.setColor(Color.WHITE);
            img.fillOval(0,0,x,y); 
            img.setTransparency(transparency);                 
        }         
        setImage(img);
    }      
    
    public void pheromoneDisipate() 
    {
        transparency = transparency - 5;        
        if (transparency <=0 ){
            getWorld().removeObject(this);
        }
        else {
            updateImage();
        }
    }
}
I am having a problem with causing the Pheromone to disipate. I can't seem to figure out the problem; all I know is it probably has something to do with the 'for' loop, but I'm not sure what exactly... It's probably a little error, but nontheless, help is greatly appreciated!
danpost danpost

2013/11/6

#
I do not see where 'pheromoneDisipate' is being called from.
JasonZhu JasonZhu

2013/11/6

#
Oh, I see. I was basing it off a method off a similar class and I guess it doesn't work the same way in this case. Thanks Dan.
danpost danpost

2013/11/6

#
It will work here. You just need to add an act method that calls the method:
public void act()
{
    pheromoneDisipate();
}
You need to login to post a reply.