Search code examples
drag-and-dropdraggablephaser-framework

How to differentiate between hold click and drag in Phaser?


How to know the distance of the Drag, unused PositionUP or onInputUp to differentiate a drag from a long click?

https://i.sstatic.net/FvVsN.pnghttp://www.html5gamedevs.com/uploads/monthly_07_2014/post-9642-0-48696600-1405440289.png

it is a some code:

var fnd = game.add.group();
var o = fnd.create(game.world.randomX, game.world.randomY, 'fon'); 
o.events.onDragStart.add(this.DragActivo, this); 
DragActive = function (image) {  
   //When something has been moved is drag but when something has been pressed for long time is clicked
};

Solution

  • You can use the property sprite.input.dragDistanceThreshold = 3; in order to start dragging only if the pointer moves a minimum amount of pixels when after onInputDown.

    Here's the doc