Navigation
These archived docs are for Phaser 2.2.2 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.

Parameters
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source code: input/Mouse.js, line 17

Public Properties

[static] LEFT_BUTTON : number

Source code: input/Mouse.js, line 164

[static] MIDDLE_BUTTON : number

Source code: input/Mouse.js, line 170

[static] NO_BUTTON : number

Source code: input/Mouse.js, line 158

[static] RIGHT_BUTTON : number

Source code: input/Mouse.js, line 176

[static] WHEEL_DOWN : number

Source code: input/Mouse.js, line 188

[static] WHEEL_UP : number

Source code: input/Mouse.js, line 182

button

Properties:
Name Type Description
button- number

The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.

Source code: input/Mouse.js, line 69

callbackContext : Object

The context under which callbacks are called.

Source code: input/Mouse.js, line 27

capture : boolean

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

Source code: input/Mouse.js, line 63

enabled : boolean

Mouse input will only be processed if enabled.

Default Value
  • true
Source code: input/Mouse.js, line 81

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
Default Value
  • null
Source code: input/Mouse.js, line 107

game : Phaser.Game

A reference to the currently running game.

Source code: input/Mouse.js, line 22

locked : boolean

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

Default Value
  • false
Source code: input/Mouse.js, line 87

mouseDownCallback : Function

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

Source code: input/Mouse.js, line 32

mouseMoveCallback : Function

This method is deprecated and should not be used. It may be removed in the future.

A callback that can be fired when the mouse is moved.

Deprecated:
  • Will be removed soon. Please use `Input.addMoveCallback` instead.
Source code: input/Mouse.js, line 38

mouseOutCallback : Function

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

Source code: input/Mouse.js, line 48

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 53

mouseUpCallback : Function

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

Source code: input/Mouse.js, line 43

mouseWheelCallback : Function

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

Source code: input/Mouse.js, line 58

pointerLock : Phaser.Signal

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

Source code: input/Mouse.js, line 99

stopOnGameOut : boolean

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

Default Value
  • false
Source code: input/Mouse.js, line 93

wheelDelta : number

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

Source code: input/Mouse.js, line 74

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 268

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 300

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 386

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 451

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 330

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 362

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 422

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 509

releasePointerLock()

Internal release pointer lock handler.

Source code: input/Mouse.js, line 534

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 480

start()

Starts the event listeners running.

Source code: input/Mouse.js, line 192

stop()

Stop the event listeners.

Source code: input/Mouse.js, line 550