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

2011/12/24

Greenfoot.getClicked(itself)

iiRainzZ iiRainzZ

2011/12/24

#
I am new to java and I was wondering how you would put theobject that is calling the getClicked() method into the parameter. Example: public class Player{ if (Greenfoot.getClicked( this object){ player = selected } } I have a way of doing this, but it is not efficient. I was wondering if there is a short syntax that can be used. Thanks!
danpost danpost

2011/12/24

#
if (Greenfoot.mouseClicked(this))
{
    // code to execute if object was clicked on
}
The this keyword refers to the current object whose act method is executing.
iiRainzZ iiRainzZ

2011/12/24

#
Thanks! Exactly what I was looking for. I didn't know that the "this" works on the whole objects, thought it was only for variables. Appreciate the great community!
You need to login to post a reply.