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

2013/11/7

Need some help.

qpommer0 qpommer0

2013/11/7

#
Hello all, I am trying to make a game when you click on one of the objects that are walking around it "kills" it. I was wondering how would you go about writing the code for the mouse clicking and killing the object. Thanks!
Zamoht Zamoht

2013/11/7

#
In the act method of the object you want to "kill" put the following code.
public void act()
{
    if (Greenfoot.mouseClicked(this))
    {
        getWorld().removeObject(this);
    }
}
qpommer0 qpommer0

2013/11/7

#
Works perfect! Thank you!
You need to login to post a reply.