Class: Mouse

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:
src/input/Mouse.js line 21

Members

<static, constant> BACK_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 165

<static, constant> FORWARD_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 171

<static, constant> LEFT_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 147

<static, constant> MIDDLE_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 153

<static, constant> NO_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 141

<static, constant> RIGHT_BUTTON : number

Type:
  • number
Source:
src/input/Mouse.js line 159

<readonly> active

Properties:
Type Description
boolean

Whether the handler has started.

Source:
src/input/Mouse.js line 79
See:

callbackContext : object

The context under which callbacks are called.

Type:
  • object
Source:
src/input/Mouse.js line 37

capture : boolean

If true the DOM mouse events will have event.preventDefault applied to them.

Type:
  • boolean
Source:
src/input/Mouse.js line 71

enabled : boolean

Whether mouse input is passed to the Input Manager and Mouse Pointer. When enabled is false, game.input and game.input.mousePointer are not updated by this handler. The handler is still running and will call any added callbacks and apply Phaser.Mouse#capture.

Type:
  • boolean
Default Value:
  • true
Source:
src/input/Mouse.js line 88

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:
src/input/Mouse.js line 104

game : Phaser.Game

A reference to the currently running game.

Type:
Source:
src/input/Mouse.js line 26

<protected> input : Phaser.Input

A reference to the Phaser Input Manager.

Type:
Source:
src/input/Mouse.js line 32

mouseDownCallback : function

A callback that can be fired when the mouse is pressed down. You should set Phaser.Input.MSPointer#pointerDownCallback as well.

Type:
  • function
Source:
src/input/Mouse.js line 44

mouseOutCallback : function

A callback that can be fired when the mouse is no longer over the game canvas. You should set Phaser.Input.MSPointer#pointerOutCallback as well.

Type:
  • function
Source:
src/input/Mouse.js line 59

mouseOverCallback : function

A callback that can be fired when the mouse enters the game canvas (usually after a mouseout). You should set Phaser.Input.MSPointer#pointerOverCallback as well.

Type:
  • function
Source:
src/input/Mouse.js line 66

mouseUpCallback : function

A callback that can be fired when the mouse is released from a pressed down state. You should set Phaser.Input.MSPointer#pointerUpCallback as well.

Type:
  • function
Source:
src/input/Mouse.js line 51

stopOnGameOut : boolean

If true Pointer.stop will be called if the mouse leaves the game canvas. You should set Phaser.Input.MSPointer#stopOnGameOut as well.

Type:
  • boolean
Source:
src/input/Mouse.js line 96

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:
src/input/Mouse.js line 252

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:
src/input/Mouse.js line 281

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:
src/input/Mouse.js line 398

onMouseOutGlobal(event)

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

Parameters:
Name Type Description
event MouseEvent

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

Source:
src/input/Mouse.js line 360

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:
src/input/Mouse.js line 437

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:
src/input/Mouse.js line 310

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:
src/input/Mouse.js line 339

start()

Starts the event listeners running.

Source:
src/input/Mouse.js line 175
Returns:
  • Whether the handler was started.
Type
boolean

stop()

Stop the event listeners.

Source:
src/input/Mouse.js line 467

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.