I need to get the coordinates of the mouse too calculate the angle between the mouse and the players character to shoot an arrow. I've been using mouse info to get this but have transitioned to a mouselistener because it gives me the coordinates relative to the frame. Can I get the coordinates of the mouse (event.getX()) on demand using the mouse listener without having to use a mouse click? if so how?
Asked
Active
Viewed 622 times
0
-
You could use a `MouseMotionListener` – John3136 Feb 24 '16 at 03:38
-
Check http://stackoverflow.com/questions/1439022/get-mouse-position It provides the solution to your problem. – Jorge Castro Feb 24 '16 at 03:39
-
This smells like an XY Problem where you're searching for the wrong solution to your problem. Likely the best solution is to in fact use a MouseListener/MouseMotionListener and to respond to its events. – Hovercraft Full Of Eels Feb 24 '16 at 03:39
-
@user3428602: that answers the *question* but is likely a bad solution for whatever underlying problem the OP has, since to use that solution, the coder must *poll* MouseInfo, and 99% of the time, listening for events is much cleaner and more efficient than polling is. – Hovercraft Full Of Eels Feb 24 '16 at 03:42
-
1Thanks guys i figured out what i need to do and posted an answer about it – squirt706 Feb 24 '16 at 03:55
1 Answers
0
Got it,
implement a MouseMotionListener and use mouse event:
public void mouseMoved(MouseEvent e) {
System.out.println(e.getX() + " " +e.getY());
}
I apologize, it wasn't working because i failed to actually implement it. :(

squirt706
- 33
- 7