Navigation
These archived docs are for Phaser 2.4.3 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser. Mouse

new Mouse(game)

The Mouse class is responsible for handling all aspects of mouse interaction with the browser.

It captures and processes mouse events that happen on the game canvas object. It also adds a single mouseup listener to window which is used to capture the mouse being released when not over the game.

You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you, including accurate button handling.

Parameters
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source code: input/Mouse.js (Line 21)

Public Properties

[static] BACK_BUTTON : number

Source code: input/Mouse.js (Line 190)

[static] FORWARD_BUTTON : number

Source code: input/Mouse.js (Line 196)

[static] LEFT_BUTTON : number

Source code: input/Mouse.js (Line 172)

[static] MIDDLE_BUTTON : number

Source code: input/Mouse.js (Line 178)

[static] NO_BUTTON : number

Source code: input/Mouse.js (Line 166)

[static] RIGHT_BUTTON : number

Source code: input/Mouse.js (Line 184)

[static] WHEEL_DOWN : number

Source code: input/Mouse.js (Line 208)

[static] WHEEL_UP : number

Source code: input/Mouse.js (Line 202)

button : number

This property was removed in Phaser 2.4 and should no longer be used. Instead please see the Pointer button properties such as Pointer.leftButton, Pointer.rightButton and so on. Or Pointer.button holds the DOM event button value if you require that.

Source code: input/Mouse.js (Line 76)

callbackContext : Object

The context under which callbacks are called.

Source code: input/Mouse.js (Line 37)

capture : boolean

If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.

Source code: input/Mouse.js (Line 67)

enabled : boolean

Mouse input will only be processed if enabled.

Default Value
  • true
Source code: input/Mouse.js (Line 89)

event :MouseEvent | null

The browser mouse DOM event. Will be null if no mouse event has ever been received. Access this property only inside a Mouse event handler and do not keep references to it.

Type
  • MouseEvent | null
Source code: input/Mouse.js (Line 115)

game : Phaser.Game

A reference to the currently running game.

Source code: input/Mouse.js (Line 26)

<internal> input : Phaser.Input

A reference to the Phaser Input Manager.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/Mouse.js (Line 32)

locked : boolean

If the mouse has been Pointer Locked successfully this will be set to true.

Source code: input/Mouse.js (Line 95)

mouseDownCallback : Function

A callback that can be fired when the mouse is pressed down.

Source code: input/Mouse.js (Line 42)

mouseOutCallback : Function

A callback that can be fired when the mouse is no longer over the game canvas.

Source code: input/Mouse.js (Line 52)

mouseOverCallback : Function

A callback that can be fired when the mouse enters the game canvas (usually after a mouseout).

Source code: input/Mouse.js (Line 57)

mouseUpCallback : Function

A callback that can be fired when the mouse is released from a pressed down state.

Source code: input/Mouse.js (Line 47)

mouseWheelCallback : Function

A callback that can be fired when the mousewheel is used.

Source code: input/Mouse.js (Line 62)

pointerLock : Phaser.Signal

This event is dispatched when the browser enters or leaves pointer lock state.

Source code: input/Mouse.js (Line 107)

stopOnGameOut : boolean

If true Pointer.stop will be called if the mouse leaves the game canvas.

Source code: input/Mouse.js (Line 101)

wheelDelta : number

The direction of the last mousewheel usage 1 for up -1 for down.

Source code: input/Mouse.js (Line 82)

Public Methods

onMouseDown(event)

The internal method that handles the mouse down event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 291)

onMouseMove(event)

The internal method that handles the mouse move event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 321)

onMouseOut(event)

The internal method that handles the mouse out event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 403)

onMouseOver(event)

The internal method that handles the mouse over event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 439)

onMouseUp(event)

The internal method that handles the mouse up event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 351)

onMouseUpGlobal(event)

The internal method that handles the mouse up event from the window.

Parameters
Name Type Description
event MouseEvent

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 381)

onMouseWheel(event)

The internal method that handles the mouse wheel event from the browser.

Parameters
Name Type Description
event MouseEvent

The native event from the browser.

Source code: input/Mouse.js (Line 463)

pointerLockChange(event)

Internal pointerLockChange handler.

Parameters
Name Type Description
event Event

The native event from the browser. This gets stored in Mouse.event.

Source code: input/Mouse.js (Line 521)

releasePointerLock()

Internal release pointer lock handler.

Source code: input/Mouse.js (Line 546)

requestPointerLock()

If the browser supports it you can request that the pointer be locked to the browser window. This is classically known as 'FPS controls', where the pointer can't leave the browser until the user presses an exit key. If the browser successfully enters a locked state the event Phaser.Mouse.pointerLock will be dispatched and the first parameter will be 'true'.

Source code: input/Mouse.js (Line 492)

start()

Starts the event listeners running.

Source code: input/Mouse.js (Line 212)

stop()

Stop the event listeners.

Source code: input/Mouse.js (Line 562)