# Class: InputHandler

## Phaser. InputHandler

Phaser.InputHandler

#### new InputHandler(sprite)

  The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `sprite` | Phaser.Sprite | The Sprite object to which this Input Handler belongs.

  Source:
    - input/InputHandler.js, line 13

### Members

#### allowHorizontalDrag

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `allowHorizontalDrag` | boolean | Controls if the Sprite is allowed to be dragged horizontally.

  Default Value:
    - true
  Source:
    - input/InputHandler.js, line 62

#### allowVerticalDrag

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `allowVerticalDrag` | boolean | Controls if the Sprite is allowed to be dragged vertically.

  Default Value:
    - true
  Source:
    - input/InputHandler.js, line 68

#### boundsRect

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `boundsRect` | Phaser.Rectangle | A region of the game world within which the sprite is restricted during drag.

  Default Value:
    - null
  Source:
    - input/InputHandler.js, line 152

#### boundsSprite

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `boundsSprite` | Phaser.Sprite | A Sprite the bounds of which this sprite is restricted during drag.

  Default Value:
    - null
  Source:
    - input/InputHandler.js, line 158

#### bringToTop

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `bringToTop` | boolean | If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 74

#### consumePointerEvent

  If this object is set to consume the pointer event then it will stop all propogation from this object on. For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `consumePointerEvent` | boolean |

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 166

#### draggable

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `draggable` | boolean | Is this sprite allowed to be dragged by the mouse? true = yes, false = no

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 146

#### enabled

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `enabled` | boolean | If enabled the Input Handler will process input requests and monitor pointer activity.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 29

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running game.

  Source:
    - input/InputHandler.js, line 23

#### isDragged

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `isDragged` | boolean | true if the Sprite is being currently dragged.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 56

#### pixelPerfectAlpha

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pixelPerfectAlpha` | number | The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.

  Default Value:
    - 255
  Source:
    - input/InputHandler.js, line 140

#### pixelPerfectClick

  Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite when it's clicked or touched. The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value. Warning: This is expensive so only enable if you really need it.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pixelPerfectClick` | number | Use a pixel perfect check when testing for clicks or touches on the Sprite.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 134

#### pixelPerfectOver

  Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite. The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value. Warning: This is expensive, especially on mobile (where it's not even needed!) so only enable if required. Also see the less-expensive InputHandler.pixelPerfectClick.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pixelPerfectOver` | number | Use a pixel perfect check when testing for pointer over.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 125

#### priorityID

  The priorityID is used to determine which game objects should get priority when input events occur. For example if you have several Sprites that overlap, by default the one at the top of the display list is given priority for input events. You can stop this from happening by controlling the priorityID value. The higher the value, the more important they are considered to the Input events.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `priorityID` | number |

  Default Value:
    - 0
  Source:
    - input/InputHandler.js, line 38

#### snapOffset

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapOffset` | Phaser.Point | A Point object that contains by how far the Sprite snap is offset.

  Default Value:
    - null
  Source:
    - input/InputHandler.js, line 80

#### snapOffsetX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapOffsetX` | number | This defines the top-left X coordinate of the snap grid.

  Default Value:
    - 0
  Source:
    - input/InputHandler.js, line 110

#### snapOffsetY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapOffsetY` | number | This defines the top-left Y coordinate of the snap grid..

  Default Value:
    - 0
  Source:
    - input/InputHandler.js, line 116

#### snapOnDrag

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapOnDrag` | boolean | When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 86

#### snapOnRelease

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapOnRelease` | boolean | When the Sprite is dragged this controls if the Sprite will be snapped on release.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 92

#### snapX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapX` | number | When a Sprite has snapping enabled this holds the width of the snap grid.

  Default Value:
    - 0
  Source:
    - input/InputHandler.js, line 98

#### snapY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `snapY` | number | When a Sprite has snapping enabled this holds the height of the snap grid.

  Default Value:
    - 0
  Source:
    - input/InputHandler.js, line 104

#### sprite

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `sprite` | Phaser.Sprite | The Sprite object to which this Input Handler belongs.

  Source:
    - input/InputHandler.js, line 18

#### useHandCursor

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `useHandCursor` | boolean | On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite.

  Default Value:
    - false
  Source:
    - input/InputHandler.js, line 44

### Methods

#### checkBoundsRect()

  Bounds Rect check for the sprite drag

  Source:
    - input/InputHandler.js, line 1310

#### checkBoundsSprite()

  Parent Sprite Bounds check for the sprite drag.

  Source:
    - input/InputHandler.js, line 1359

#### checkPixel(x, y, pointer) → {boolean}

  Runs a pixel perfect check against the given x/y coordinates of the Sprite this InputHandler is bound to. It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `x` | number |  | The x coordinate to check.
  `y` | number |  | The y coordinate to check.
  `pointer` | Phaser.Pointer | <optional> | The pointer to get the x/y coordinate from if not passed as the first two parameters.

  Source:
    - input/InputHandler.js, line 672

  ##### Returns:

  true if there is the alpha of the pixel is >= InputHandler.pixelPerfectAlpha

  Type
    boolean

#### checkPointerDown(pointer) → {boolean}

  Checks if the given pointer is over this Sprite and can click it.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 612

  ##### Returns:

  True if the pointer is down, otherwise false.

  Type
    boolean

#### checkPointerOver(pointer) → {boolean}

  Checks if the given pointer is over this Sprite.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 642

  ##### Returns:

  Type
    boolean

#### destroy()

  Clean up memory.

  Source:
    - input/InputHandler.js, line 367

#### disableDrag()

  Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks.

  Source:
    - input/InputHandler.js, line 1151

#### disableSnap()

  Stops the sprite from snapping to a grid during drag or release.

  Source:
    - input/InputHandler.js, line 1299

#### downDuration(pointer) → {number}

  If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 1092

  ##### Returns:

  The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.

  Type
    number

#### enableDrag(lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)

  Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `lockCenter` | boolean | <optional> | false | If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
  `bringToTop` | boolean | <optional> | false | If true the Sprite will be bought to the top of the rendering list in its current Group.
  `pixelPerfect` | boolean | <optional> | false | If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
  `alphaThreshold` | boolean | <optional> | 255 | If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed.
  `boundsRect` | Phaser.Rectangle | <optional> | null | If you want to restrict the drag of this sprite to a specific Rectangle, pass the Phaser.Rectangle here, otherwise it's free to drag anywhere.
  `boundsSprite` | Phaser.Sprite | <optional> | null | If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here.

  Source:
    - input/InputHandler.js, line 1111

#### enableSnap(snapX, snapY, onDrag, onRelease, snapOffsetX, snapOffsetX)

  Make this Sprite snap to the given grid either during drag or when it's released. For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `snapX` | number |  |  | The width of the grid cell to snap to.
  `snapY` | number |  |  | The height of the grid cell to snap to.
  `onDrag` | boolean | <optional> | true | If true the sprite will snap to the grid while being dragged.
  `onRelease` | boolean | <optional> | false | If true the sprite will snap to the grid when released.
  `snapOffsetX` | number | <optional> | 0 | Used to offset the top-left starting point of the snap grid.
  `snapOffsetX` | number | <optional> | 0 | Used to offset the top-left starting point of the snap grid.

  Source:
    - input/InputHandler.js, line 1272

#### justOut(pointer, delay) → {boolean}

  Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |
  `delay` | number | The time below which the pointer is considered as just out.

  Source:
    - input/InputHandler.js, line 1025

  ##### Returns:

  Type
    boolean

#### justOver(pointer, delay) → {boolean}

  Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |
  `delay` | number | The time below which the pointer is considered as just over.

  Source:
    - input/InputHandler.js, line 1009

  ##### Returns:

  Type
    boolean

#### justPressed(pointer, delay) → {boolean}

  Returns true if the pointer has touched or clicked on the Sprite within the specified delay time (defaults to 500ms, half a second)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |
  `delay` | number | The time below which the pointer is considered as just over.

  Source:
    - input/InputHandler.js, line 1041

  ##### Returns:

  Type
    boolean

#### justReleased(pointer, delay) → {boolean}

  Returns true if the pointer was touching this Sprite, but has been released within the specified delay time (defaults to 500ms, half a second)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |
  `delay` | number | The time below which the pointer is considered as just out.

  Source:
    - input/InputHandler.js, line 1057

  ##### Returns:

  Type
    boolean

#### overDuration(pointer) → {number}

  If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 1073

  ##### Returns:

  The number of milliseconds the pointer has been over the Sprite, or -1 if not over.

  Type
    number

#### pointerDown(pointer) → {boolean}

  If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 454

  ##### Returns:

  Type
    boolean

#### pointerDragged(pointer) → {boolean}

  Is this sprite being dragged by the mouse or not?

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 598

  ##### Returns:

  True if the pointer is dragging an object, otherwise false.

  Type
    boolean

#### pointerOut(index) → {boolean}

  Is the Pointer outside of this Sprite?

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `index` | number | <optional> | The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.

  Source:
    - input/InputHandler.js, line 540

  ##### Returns:

  True if the given pointer (if a index was given, or any pointer if not) is out of this object.

  Type
    boolean

#### pointerOver(index) → {boolean}

  Is the Pointer over this Sprite?

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `index` | number | <optional> | The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.

  Source:
    - input/InputHandler.js, line 510

  ##### Returns:

  True if the given pointer (if a index was given, or any pointer if not) is over this object.

  Type
    boolean

#### pointerTimeDown(pointer) → {number}

  A timestamp representing when the Pointer first touched the touchscreen.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 482

  ##### Returns:

  Type
    number

#### pointerTimeOut(pointer) → {number}

  A timestamp representing when the Pointer left the touchscreen.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 584

  ##### Returns:

  Type
    number

#### pointerTimeOver(pointer) → {number}

  A timestamp representing when the Pointer first touched the touchscreen.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 570

  ##### Returns:

  Type
    number

#### pointerTimeUp(pointer) → {number}

  A timestamp representing when the Pointer left the touchscreen.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 496

  ##### Returns:

  Type
    number

#### pointerUp(pointer) → {boolean}

  If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 468

  ##### Returns:

  Type
    boolean

#### pointerX(pointer) → {number}

  The x coordinate of the Input pointer, relative to the top-left of the parent Sprite. This value is only set when the pointer is over this Sprite.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 424

  ##### Returns:

  The x coordinate of the Input pointer.

  Type
    number

#### pointerY(pointer) → {number}

  The y coordinate of the Input pointer, relative to the top-left of the parent Sprite This value is only set when the pointer is over this Sprite.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 439

  ##### Returns:

  The y coordinate of the Input pointer.

  Type
    number

#### reset()

  Resets the Input Handler and disables it.

  Source:
    - input/InputHandler.js, line 319

#### setDragLock(allowHorizontal, allowVertical)

  Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `allowHorizontal` | boolean | <optional> | true | To enable the sprite to be dragged horizontally set to true, otherwise false.
  `allowVertical` | boolean | <optional> | true | To enable the sprite to be dragged vertically set to true, otherwise false.

  Source:
    - input/InputHandler.js, line 1256

#### start(priority, useHandCursor) → {Phaser.Sprite}

  Starts the Input Handler running. This is called automatically when you enable input on a Sprite, or can be called directly if you need to set a specific priority.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `priority` | number | Higher priority sprites take click priority over low-priority sprites when they are stacked on-top of each other.
  `useHandCursor` | boolean | If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers)

  Source:
    - input/InputHandler.js, line 212

  ##### Returns:

  The Sprite object to which the Input Handler is bound.

  Type
    Phaser.Sprite

#### startDrag(pointer)

  Called by Pointer when drag starts on this Sprite. Should not usually be called directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 1171

#### stop()

  Stops the Input Handler from running.

  Source:
    - input/InputHandler.js, line 347

#### stopDrag(pointer)

  Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 1221

#### <protected> update(pointer)

  Update.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 724

#### updateDrag(pointer) → {boolean}

  Updates the Pointer drag on this Sprite.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pointer` | Phaser.Pointer |

  Source:
    - input/InputHandler.js, line 934

  ##### Returns:

  Type
    boolean

#### <protected> validForInput(highestID, highestRenderID) → {boolean}

  Checks if the object this InputHandler is bound to is valid for consideration in the Pointer move event. This is called by Phaser.Pointer and shouldn't typically be called directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `highestID` | number | The highest ID currently processed by the Pointer.
  `highestRenderID` | number | The highest Render Order ID currently processed by the Pointer.

  Source:
    - input/InputHandler.js, line 393

  ##### Returns:

  True if the object this InputHandler is bound to should be considered as valid for input detection.

  Type
    boolean