1

new to Java here but i have been experimenting...

I am trying to achieve this in Greenfoot: I want to have a mouse click on an object (Actor) and it disappears from the world. This is my code so far:

public void act() 
    {
        disappear();
    }    

    public void disappear(){
        if(Greenfoot.mouseClicked(this)){
            getWorld().removeObject(this);
        }
    }

From my understanding, when the mouse is clicked, then it will remove the object from the world... but the object still doesn't disappear, what am i missing here?

Many thanks!

jonprasetyo
  • 3,356
  • 3
  • 32
  • 48

1 Answers1

-1

You can regist the action

getWorld().removeObject(this);

to the mouse clicked event list.

Maybe show us the class archi of your system could give us more information.

zwang
  • 685
  • 1
  • 8
  • 13