Class Mouse

Mouse instance for input in sync with the running application.

Hierarchy (view full)

Constructors

  • Constructor for the mouse handler.

    Parameters

    • Optionalelement: HTMLElement

      Optional HTML element to attach the mouse tracking events. By default the "window" object is used.

    • touchHandlers: boolean = false

      Flag to indicate if touch events should be created for the mouse instance. (To allow interation on touch based devices).

    Returns Mouse

Properties

canvas: HTMLCanvasElement = null

Canvas attached to this mouse instance used to calculate position and delta in canvas space coordinates.

delta: Vector2 = ...

Mouse movement (coordinates in window space).

domElement: HTMLElement | Window = null

DOM element where to attach the mouse events.

doubleClicked: boolean = false

Indicates if some button of the mouse was just double-clicked.

events: EventManager = null

Event manager used to manage the mouse events.

keys: Button[] = ...

Array with mouse buttons status.

position: Vector2 = ...

Mouse position inside the window (coordinates in window space).

positionUpdated: boolean = false

Indicates if the mouse position changed mid-frames.

touchHandlers: boolean = false

If true touch events are also considered in the mouse object.

wheel: number = 0

Mouse scroll wheel movement.

wheelUpdated: boolean = false

Indicates if the wheel position changed mid-frames.

Methods

  • Check if Mouse button was double-clicked.

    Returns boolean

  • Check if a mouse button was just pressed.

    Parameters

    • button: number

      Button to check the state of.

    Returns boolean

  • Check if a mouse button was just released.

    Parameters

    • button: number

      Button to check the state of.

    Returns boolean

  • Check if mouse button is currently pressed.

    Parameters

    • button: number

    Returns boolean

  • Create mouse handler events.

    Events created are managed by the event manager instance.

    Returns void

  • Check if mouse is inside attached canvas (updated async).

    Returns boolean

  • Canvas to be used for coordinates calculation relative to that canvas.

    Parameters

    • canvas: HTMLCanvasElement

    Returns void

  • Set mouse lock state.

    When the mouse gets locked into a element is can no longer move around.

    Usefull for games and application that require delta mouse movement (e.g. FPS camera)

    Parameters

    • value: boolean

      Define if the lock should be active or disable.

    Returns void

  • Update mouse buttons state, position, wheel and delta synchronously.

    Should be called every frame before reading values from the mouse.

    Returns void

  • Update a mouse button.

    Parameters

    • button: number
    • action: number

    Returns void

  • Update mouse position.

    Parameters

    • x: number
    • y: number
    • xDiff: number
    • yDiff: number

    Returns void