new InputHandler(game)
Constructor for Phaser InputHandler.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Sprite | Description. |
- Source:
Members
-
allowHorizontalDrag
-
- Default Value:
- true
- Source:
Properties:
Name Type Description allowHorizontalDragboolean Description.
-
allowVerticalDrag
-
- Default Value:
- true
- Source:
Properties:
Name Type Description allowVerticalDragboolean Description.
-
boundsRect
-
- Default Value:
- null
- Source:
Properties:
Name Type Description boundsRectDescription A region of the game world within which the sprite is restricted during drag.
-
boundsSprite
-
- Default Value:
- null
- Source:
Properties:
Name Type Description boundsSpriteDescription A Sprite the bounds of which this sprite is restricted during drag.
-
bringToTop
-
- Default Value:
- false
- Source:
Properties:
Name Type Description bringToTopboolean Description.
-
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.
- Default Value:
- false
- Source:
Properties:
Name Type Description consumePointerEventboolean -
draggable
-
- Default Value:
- false
- Source:
Properties:
Name Type Description draggableboolean Is this sprite allowed to be dragged by the mouse? true = yes, false = no
-
enabled
-
- Default Value:
- false
- Source:
Properties:
Name Type Description enabledboolean Description.
-
first
-
- Source:
Properties:
Name Type Description firstDescription Description.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game A reference to the currently running game.
-
isDragged
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isDraggedboolean Description.
-
last
-
- Source:
Properties:
Name Type Description lastDescription Description.
-
next
-
- Default Value:
- null
- Source:
Properties:
Name Type Description nextDescription Description.
-
parent
-
- Default Value:
- null
- Source:
Properties:
Name Type Description parentDescription Description.
-
pixelPerfect
-
- Default Value:
- false
- Source:
Properties:
Name Type Description pixelPerfectnumber Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
-
pixelPerfectAlpha
-
- Default Value:
- 255
- Source:
Properties:
Name Type Description pixelPerfectAlphanumber The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.
-
prev
-
- Default Value:
- null
- Source:
Properties:
Name Type Description prevDescription Description.
-
priorityID
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description priorityIDnumber The PriorityID controls which Sprite receives an Input event first if they should overlap.
-
snapOffset
-
- Default Value:
- null
- Source:
Properties:
Name Type Description snapOffsetDescription Description.
-
snapOnDrag
-
- Default Value:
- false
- Source:
Properties:
Name Type Description snapOnDragboolean Description.
-
snapOnRelease
-
- Default Value:
- false
- Source:
Properties:
Name Type Description snapOnReleaseboolean Description.
-
snapX
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description snapXnumber Description.
-
snapY
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description snapYnumber Description.
-
sprite
-
- Source:
Properties:
Name Type Description spritePhaser.Sprite Description.
-
useHandCursor
-
- Default Value:
- false
- Source:
Properties:
Name Type Description useHandCursorboolean Description.
Methods
-
checkBoundsRect()
-
Bounds Rect check for the sprite drag
- Source:
-
checkBoundsSprite()
-
Parent Sprite Bounds check for the sprite drag.
- Source:
-
checkPixel(x, y) → {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 Description xnumber The x coordinate to check.
ynumber The y coordinate to check.
- Source:
Returns:
true if there is the alpha of the pixel is >= InputHandler.pixelPerfectAlpha
- Type
- boolean
-
checkPointerOver(pointer) → {boolean}
-
Checks if the given pointer is over this Sprite.
Parameters:
Name Type Description pointerPointer - Source:
Returns:
- Type
- boolean
-
destroy()
-
Clean up memory.
- Source:
-
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:
-
disableSnap()
-
Stops the sprite from snapping to a grid during drag or release.
- Source:
-
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 pointerPointer - Source:
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 Description lockCenterIf 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.
bringToTopIf true the Sprite will be bought to the top of the rendering list in its current Group.
pixelPerfectIf true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
alphaThresholdIf using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)
boundsRectIf you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere
boundsSpriteIf you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here
- Source:
-
enableSnap(snapX, snapY, onDrag, onRelease)
-
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 Description snapXThe width of the grid cell in pixels
snapYThe height of the grid cell in pixels
onDragIf true the sprite will snap to the grid while being dragged
onReleaseIf true the sprite will snap to the grid when released
- Source:
-
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 pointerPointer delaynumber The time below which the pointer is considered as just out.
- Source:
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 pointerPointer delaynumber The time below which the pointer is considered as just over.
- Source:
Returns:
- Type
- boolean
-
justPressed(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 pointerPointer delaynumber The time below which the pointer is considered as just over.
- Source:
Returns:
- Type
- boolean
-
justReleased(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 pointerPointer delaynumber The time below which the pointer is considered as just out.
- Source:
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 pointerPointer - Source:
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 pointerPointer - Source:
Returns:
- Type
- boolean
-
pointerOut(index) → {boolean}
-
Is the Pointer outside of this Sprite?
Parameters:
Name Type Argument Description indexnumber <optional>
The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
- Source:
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 indexnumber <optional>
The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
- Source:
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 pointerPointer - Source:
Returns:
- Type
- number
-
pointerTimeOut(pointer) → {number}
-
A timestamp representing when the Pointer left the touchscreen.
Parameters:
Name Type Description pointerPointer - Source:
Returns:
- Type
- number
-
pointerTimeOut(pointer) → {number}
-
Is this sprite being dragged by the mouse or not?
Parameters:
Name Type Description pointerPointer - Source:
Returns:
- Type
- number
-
pointerTimeOver(pointer) → {number}
-
A timestamp representing when the Pointer first touched the touchscreen.
Parameters:
Name Type Description pointerPointer - Source:
Returns:
- Type
- number
-
pointerTimeUp(pointer) → {number}
-
A timestamp representing when the Pointer left the touchscreen.
Parameters:
Name Type Description pointerPointer - Source:
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 pointerPointer - Source:
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 pointerPointer - Source:
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 pointerPointer - Source:
Returns:
The y coordinate of the Input pointer.
- Type
- number
-
reset()
-
Description.
- Source:
-
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 Description allowHorizontalTo enable the sprite to be dragged horizontally set to true, otherwise false
allowVerticalTo enable the sprite to be dragged vertically set to true, otherwise false
- Source:
-
start(priority, useHandCursor) → {Phaser.Sprite}
-
Description.
Parameters:
Name Type Description prioritynumber Description.
useHandCursorboolean Description.
- Source:
Returns:
Description.
- Type
- Phaser.Sprite
-
startDrag()
-
Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
- Source:
-
stop()
-
Description.
- Source:
-
stopDrag()
-
Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
- Source:
-
update(pointer)
-
Update.
Parameters:
Name Type Description pointerPointer - Source:
-
updateDrag(pointer) → {boolean}
-
Updates the Pointer drag on this Sprite.
Parameters:
Name Type Description pointerPointer - Source:
Returns:
- Type
- boolean