Navigation
These archived docs are for Phaser 2.3.0 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 propagate 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 269)

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 301)

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 387)

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 452)

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 331)

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 363)

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 423)

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 510)

releasePointerLock()

Internal release pointer lock handler.

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

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 481)

start()

Starts the event listeners running.

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

stop()

Stop the event listeners.

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