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

2014/7/14

mouse input?

blangley83 blangley83

2014/7/14

#
I am looking to find which methods in class Greenfoot can handle mouse input? I looked them up and am not sure if these are all of them or not? This is for assignment 8.7 mousePressed public static boolean mousePressed(java.lang.Object obj) True if the mouse has been pressed (changed from a non-pressed state to being pressed) on the given object. If the parameter is an Actor the method will only return true if the mouse has been pressed on the given actor. If there are several actors at the same place, only the top most actor will receive the press. If the parameter is a World then true will be returned if the mouse was pressed on the world background. If the parameter is null, then true will be returned for any mouse press, independent of the target pressed on. Parameters: obj - Typically one of Actor, World or null Returns: True if the mouse has been pressed as explained above mouseClicked public static boolean mouseClicked(java.lang.Object obj) True if the mouse has been clicked (pressed and released) on the given object. If the parameter is an Actor the method will only return true if the mouse has been clicked on the given actor. If there are several actors at the same place, only the top most actor will receive the click. If the parameter is a World then true will be returned if the mouse was clicked on the world background. If the parameter is null, then true will be returned for any click, independent of the target clicked on. Parameters: obj - Typically one of Actor, World or null Returns: True if the mouse has been clicked as explained above mouseDragged public static boolean mouseDragged(java.lang.Object obj) True if the mouse is currently being dragged on the given object. The mouse is considered to be dragged on an object if the drag started on that object - even if the mouse has since been moved outside of that object. If the parameter is an Actor the method will only return true if the drag started on the given actor. If there are several actors at the same place, only the top most actor will receive the drag. If the parameter is a World then true will be returned if the drag action was started on the world background. If the parameter is null, then true will be returned for any drag action, independent of the target clicked on. Parameters: obj - Typically one of Actor, World or null Returns: True if the mouse has been dragged as explained above mouseDragEnded public static boolean mouseDragEnded(java.lang.Object obj) True if a mouse drag has ended. This happens when the mouse has been dragged and the mouse button released. If the parameter is an Actor the method will only return true if the drag started on the given actor. If there are several actors at the same place, only the top most actor will receive the drag. If the parameter is a World then true will be returned if the drag action was started on the world background. If the parameter is null, then true will be returned for any drag action, independent of the target clicked on. Parameters: obj - Typically one of Actor, World or null Returns: True if the mouse has been dragged as explained above mouseMoved public static boolean mouseMoved(java.lang.Object obj) True if the mouse has been moved on the given object. The mouse is considered to be moved on an object if the mouse pointer is above that object. If the parameter is an Actor the method will only return true if the move is on the given actor. If there are several actors at the same place, only the top most actor will receive the move. If the parameter is a World then true will be returned if the move was on the world background. If the parameter is null, then true will be returned for any move, independent of the target under the move location. Parameters: obj - Typically one of Actor, World or null Returns: True if the mouse has been moved as explained above getMouseInfo
lordhershey lordhershey

2014/7/14

#
 MouseInfo mouse = Greenfoot.getMouseInfo();
        if(null != mouse)
        {
            int mx = mouse.getX();
            int my = mouse.getY();
            
            int cx = 240;
            int cy = 240;
            
            double rad = Math.atan2((double)(cy-my),(double)(cx-mx));
            
            double degree = rad * ratio + 90;
            
            double dx = -Math.cos(rad) * radius + cx;
            double dy = -Math.sin(rad) * radius + cy;
            
            setLocation((int)dx,(int)dy);
            setRotation((int)degree);
        }
You get the mouse, check to make sure it is not null, then yse the getX() and getY() to figure out where on the screen it is.
blangley83 blangley83

2014/7/14

#
Awesome, thanks!
danpost danpost

2014/7/14

#
The five methods you mentioned above are all the Greenfoot class methods that deal with mouse input. The 'getMouseInfo' method does not deal with input; but, instead, provides a way to get more information about the mouse input (actor clicked, buttons pressed, click count and location of mouse).
You need to login to post a reply.