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

2017/7/9

mouseclicked

Williamli Williamli

2017/7/9

#
I dont know how to do the mouseclicked, the documentation says mouseclicked, but it doesn't work.
danpost danpost

2017/7/9

#
Williamli wrote...
I dont know how to do the mouseclicked, the documentation says mouseclicked, but it doesn't work.
Show what code you tried. We cannot correct unseen codes.
Williamli Williamli

2017/7/9

#
1
if(Greenfoot.mouseclicked)
danpost danpost

2017/7/9

#
The method name is 'mouseClicked' (with a uppercase 'C'); and the documentation says it requires a parameter -- an instance of some Object type (typically a World or Actor object, or 'null', where any click will return a 'true' value):
1
2
3
if (Greenfoot.mouseClicked(null)) // true for any click
// or
if (Greenfoot.mouseClicked(this)) // true if current object is clicked
You could even have references to, let us say, Button objects in your World subclass:
1
2
Actor btnYes = new Button("Yes");
Actor btnNo = new Button("No");
and have the act method in that same world class check for clicks on them:
1
2
3
4
5
6
7
8
if (Greenfoot.mouseClicked(btnYes))
{
    // some action
}
if (Greenfoot.mouseClicked(btnNo))
{
    // some other action
}
You need to login to post a reply.