MouseHandler

Mouse input handler.

Constructor

new MouseHandler(parentHandler, condition)

Create a new mouse input handler.
Parameters:
NameTypeDescription
parentHandlerEventHandler | EventHandlerLayerParent event handler or layer
conditionfunctionFunction for checking whether events should run

Extends

Members

pos

Get the current position of the mouse.

Methods

(protected) _doDown(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

(protected) _doPress(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

(protected) _doRelease(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

capture() → {boolean}

Capture and "claim" the mouse
Returns:
Whether capture was successful
Type: 
boolean

destructor()

Handle deletion of the handler and its input listeners.

gameFocused() → {boolean}

Check if the game is in focus (user is not focused on input).
Returns:
Whether the game is focused
Type: 
boolean

isCaptured() → {boolean}

Check if the mouse is currently captured.
Returns:
Whether the mouse is captured
Type: 
boolean

isDown(key) → {boolean}

Check if a key is currently being held down.
Parameters:
NameTypeDescription
keyanyKey to check for
Returns:
Whether key is being held down
Type: 
boolean

isInWindow() → {boolean}

Check if the mouse is currently within the canvas.
Returns:
Whether mouse is within canvas
Type: 
boolean

onMove(func)

Add a function to listen for mouse movement.
Parameters:
NameTypeDescription
funcfunctionFunction to run upon mouse movement

onPress(key, func)

Add an event to listen for a specific key press. Will fire once.
Parameters:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing

onRelease(key, func)

Add an event to listen for a specific key release. Will fire once.
Parameters:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing

onScroll(func)

Add a function to listen for the mouse scroll wheel.
Parameters:
NameTypeDescription
funcfunctionFunction to run upon scrolling

release()

Release the mouse.

setCursor(cursor)

Set the mouse cursor ("default" by default).
Parameters:
NameTypeDefaultDescription
cursorstringdefaultNew cursor

whileDown(key, func)

Add an event to fire while a key is pressed down. Fires continuously.
Parameters:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing