If mouse moves (at all), get MouseInfo object and set actor's location to mouse's x and y.
... by using Greenfoot.getMouseInfo() which returns an instance of MouseInfo. You need to check that it is not null, then you can access the location via getX() and getY(). You need to update this every frame though, because a MouseInfo instance is like a snapshot and only represents the mouse in the moment that is was requested in.
a MouseInfo instance is like a snapshot and only represents the mouse in the moment that is was requested in.
Actually, greenfoot collects mouse action information between act cycles whether it is requested or not (while the scenario is in a running state).
RcCookie wrote...
You need to check that it is not null
This is not necessary if you find a mouse action has occurred. That is, if one of the Greenfoot class mouse methods is found to be true (mouseClicked, mouseMoved, mousePresssed, mouseDragged, etc).
Yeah, but what I meant was that you cannot just get one MouseInfo instance and use it for the rest of the time. Also it seems unreasonable to first check if the mouse moved and then get the mouse info again.
Yeah, but what I meant was that you cannot just get one MouseInfo instance and use it for the rest of the time. Also it seems unreasonable to first check if the mouse moved and then get the mouse info again.
Either way, you perform one check that verifies that a MouseiInfo object will not be null. Also, in this case of PascalFisher, no actor repositioning is required unless the mouse is moved.