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

2020/12/6

can I set an Image for the mouse?

PascalFischer PascalFischer

2020/12/6

#
is it possible to set an Image, which will be on the exact same position as the mouse, you are playing with?
danpost danpost

2020/12/6

#
PascalFischer wrote...
is it possible to set an Image, which will be on the exact same position as the mouse, you are playing with?
Yes -- you can have an actor follow the mouse.
PascalFischer PascalFischer

2020/12/7

#
how can I do this?
danpost danpost

2020/12/7

#
PascalFischer wrote...
how can I do this?
If mouse moves (at all), get MouseInfo object and set actor's location to mouse's x and y.
RcCookie RcCookie

2020/12/8

#
danpost wrote...
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.
danpost danpost

2020/12/9

#
RcCookie wrote...
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).
RcCookie RcCookie

2020/12/9

#
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.
danpost danpost

2020/12/9

#
RcCookie wrote...
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.
You need to login to post a reply.