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

2015/3/26

If Actor Clicked

LamboCreeper LamboCreeper

2015/3/26

#
Hey! How do I detect if my actor is clicked by the mouse?
Super_Hippo Super_Hippo

2015/3/26

#
1
2
3
4
5
6
7
8
9
if (Greenfoot.mouseClicked(this))
{
    //...
}
//or
if (Greenfoot.mousePressed(this))
{
    //...
}
'mouseClicked' returns true if the mouse was pressed on the object and released afterwards. 'mousePressed' returns true when the mouse was pressed on the object. You can use this in a class code. Then 'this' is the object of the class in which this code is executed. Instead of 'this', you can also use 'null' (any click (like descripted above) returns true) or a reference to an actor (not a class). If you use 'this' in a world subclass, it returns true if the click was made on the background of the world (so on no actor).
You need to login to post a reply.