Mouse
Mouse Functions
There are two ways you can get information from the user's mouse: Event Listeners and Direct Polling. With an Event Listener, you write a function that gets called automatically when the user uses their mouse. With Direct Polling, you can ask about the mouse whenever you want, which you would typically do during each frame in your update world function.You can also control the mouse pointer - showing and hiding it.
- Mouse Direct Polling
getMousePosition
getMousePosition
Returns the current position of the mouse.
Returns
array
an array that contains the x and y coordinates of the mouse
getMouseButton
getMouseButton
Returns whether a given mouse button is pressed or not.
button
*
number
-
a number indicating which button to check (1 for left, 2 for middle, 3 for right) (use 1 on a Mac with one button)
Returns
boolean
true
means that button is currently pressed and false
means it is not
- Mouse Event Listeners
onMousePress
onMousePress
Registers your function that listens for mouse pressed events.
listenerFunction
*
function
the listener function that you wrote.
Your listener function must take four arguments:
the world
the x coordinate where the mouse was when the button was pressed
the y coordinate where the mouse was when the button was pressed
a number indicating which button was pressed (1 for left, 2 for middle, 3 for right) (use 1 for a Mac with one button)
Returns
nothing
onMouseRelease
onMouseRelease
Registers your function that listens for mouse pressed events.
listenerFunction
*
function
the listener function that you wrote. Your listener function must take four arguments:
the world
the x coordinate where the mouse was when the button was pressed
the y coordinate where the mouse was when the button was pressed
a number indicating which button was pressed (1 for left, 2 for middle, 3 for right) (use 1 for a Mac with one button)
Returns
nothing
onWheelForward
onWheelForward
Registers your function that listens for mouse pressed events.
listenerFunction
*
function
the listener function that you wrote. Your listener function must take three arguments:
the world
the x coordinate where the mouse was when the button was released
the y coordinate where the mouse was when the button was released
Returns
nothing
onWheelBackward
onWheelBackward
Registers your function that listens for mouse pressed events.
listenerFunction
*
function
the listener function that you wrote. Your listener function must take three arguments:
the world
the x coordinate where the mouse was when the wheel was rotated
the y coordinate where the mouse was when the wheel was rotated
Returns
nothing
onMouseMotion
onMouseMotion
Registers your function that listens for mouse pressed events.
listenerFunction
*
function
the listener function that you wrote. Your listener function must take eight arguments:
the world
the x coordinate that the mouse moved to
the y coordinate that the mouse moved to
the amount by which the x coordinate changed during this move (may be positive or negative)
the amount by which the y coordinate changed during this move (may be positive or negative)
a boolean for mouse button 1 (true if it was pressed, and false if it was not)
a boolean for mouse button 2 (true if it was pressed, and false if it was not)
a boolean for mouse button 3 (true if it was pressed, and false if it was not)
Returns
nothing
- Mouse Control
hideMouse
hideMouse
Makes the mouse cursor invisible.
Returns
nothing
showMouse
showMouse
Makes the mouse cursor visible - this is only needed if you have previously called hideMouse()
.
Returns
nothing
Last updated