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

2020/10/27

Mouse click hold ?

Paul12345 Paul12345

2020/10/27

#
I'm trying to track the mouse position from the moment I press left click, until I release the button. How can I achieve this ? MouseInfo for some reason registers every mouse movement (while left click is pressed) as another click.
RcCookie RcCookie

2020/10/28

#
You need to track the mouse‘s state:
1
2
3
4
5
// Globally
boolean pressed = false;
// In act method
if(Greenfoot.mousePressed(null)) pressed = true;
else if(Greenfoot.mouseClicked(null)) pressed = false;
If you want pressed only to be true if the mouse was clicked onto a specific actor, replace the null in line 4 with the specific actor, BUT NOT in line 5!
1
if(Greenfoot.mousePressed(theActor)) ...
You need to login to post a reply.