InputHandler#enableDrag()

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

Allow this Sprite to be dragged by any valid pointer.

When the drag begins the Sprite.events.onDragStart event will be dispatched.

When the drag completes by way of the user letting go of the pointer that was dragging the sprite, the Sprite.events.onDragStop event is dispatched.

You can control the thresholds over when a drag starts via the properties:

Pointer.dragDistanceThreshold the distance, in pixels, that the pointer has to move
before the drag will start.

Pointer.dragTimeThreshold the time, in ms, that the pointer must be held down on
the Sprite before the drag will start.

You can set either (or both) of these properties after enabling a Sprite for drag.

For the duration of the drag the Sprite.events.onDragUpdate event is dispatched. This event is only dispatched when the pointer actually
changes position and moves. The event sends 5 parameters: sprite, pointer, dragX, dragY and snapPoint.

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 code: input/InputHandler.js (Line 1383)
doc_phaser
2017-02-14 10:53:20
Comments
Leave a Comment

Please login to continue.