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

2013/4/3

Trying to make something disappear when I click the mouse on it. Help?

Kiara Kiara

2013/4/3

#
I have a game with a mouse and a spider. When the cursor (or mouse) clicks on the spider, it should disappear. It's not working, obviously. Help me? The code looks like this. public void clickSpider() { if(Greenfoot.mouseClicked(spider)) { getWorld().removeObject(spider); } } ps. I am a very VERY new programmer.
danpost danpost

2013/4/3

#
I will presume that this code is in the 'Spider' class; and this method is called from the 'act' method. The keyword that refers to the object that is being 'act'ed on is 'this'. Therefore:
public void clickSpider()
{
    if (Greenfoot.mouseClicked(this))
    {   
        getWorld().removeObject(this);
    }
}
Kiara Kiara

2013/4/4

#
yay! It worked! Thanks, Danpost!
You need to login to post a reply.