Class: Mouse

Mouse

new Mouse(canvas)

Mouse and touch input handling. An instance of Mouse is available as Splat.Game#mouse. The first touch will emulates a mouse press with button 0. This means you can use the mouse (Mouse#isPressed/Mouse#consumePressed) APIs and your game will work on touch screens (as long as you only need the left button. A mouse press will emulate a touch if the device does not support touch. This means you can use Mouse#touches, and your game will still work on a PC with a mouse. Also, if you call Mouse#consumePressed with button 0, it will add a `consumed:true` field to all current touches. This will help you prevent processing a touch multiple times.
Parameters:
Name Type Description
canvas external:canvas The canvas to listen for events on.
Source:

Members

onmouseup :onmouseupHandler

A function that will be called when a mouse button is released, or a touch has stopped. This is useful for opening a URL with Splat.openUrl to avoid popup blockers.
Type:
Source:

touches :Array

An array of the current touches on a touch screen device. Each touch has a `x`, `y`, and `id` field.
Type:
  • Array
Source:

x :number

The x coordinate of the cursor relative to the left side of the canvas.
Type:
  • number
Source:

y :number

The y coordinate of the cursor relative to the top of the canvas.
Type:
  • number
Source:

Methods

consumePressed(button, xopt, yopt, widthopt, heightopt) → {boolean}

Test if a mouse button is currently pressed, and was newly pressed down since the last call to consumePressed. If you call this with button 0, it will add a `consumed:true` field to all current touches. This will help you prevent processing a touch multiple times.
Parameters:
Name Type Attributes Description
button number The button number to test.
x number <optional>
The left edge of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
y number <optional>
The top edge of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
width number <optional>
The width of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
height number <optional>
The height of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
Source:
Returns:
Type
boolean

isPressed(button, xopt, yopt, widthopt, heightopt) → {boolean}

Test if a mouse button is currently pressed.
Parameters:
Name Type Attributes Description
button number The button number to test. Button 0 is typically the left mouse button, as well as the first touch location.
x number <optional>
The left edge of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
y number <optional>
The top edge of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
width number <optional>
The width of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
height number <optional>
The height of a rectangle to restrict the test to. If the mouse position is outside of this rectangle, the button will not be considered pressed.
Source:
Returns:
Type
boolean

supportsTouch() → {boolean}

Test whether the device supports touch events. This is useful to customize messages to say either "click" or "tap".
Source:
Returns:
Type
boolean