phaser icon indicating copy to clipboard operation
phaser copied to clipboard

[Regression] Input dragDistanceThreshold no longer works in 3.18.0 and 3.18.1

Open muliawanw opened this issue 7 years ago • 3 comments

Tested it on https://phaser.io/examples/v3/view/input/dragging/drag-distance-threshold

Observe on version 3.18.0 and 3.18.1 the eyes sprite will turned tinted (red) as soon as the mouse button is pressed but not moved.

Compare with version 3.17.0, the eyes sprite will only turned red after the mouse is pressed and moved beyond the threshold as expected.

muliawanw avatar Jul 21 '19 02:07 muliawanw

dragTimeThreshold also no longer works. (https://phaser.io/examples/v3/view/input/dragging/drag-time-threshold#)

DCoin avatar Aug 24 '19 23:08 DCoin

I think I've found the source (or rather sources) for this:

Unless BOTH dragDistanceThreshold and dragTimeThreshold were set it was jumping right to drag state 3 and never waiting for the threshold to be reached. This was caused by line 1193 in inputPlugin.js using || instead of && (so if either one of the two was not set, it would skip threshold checking completely).

In addition, in the move to the new input system in 3.18, the massive processDragEvents() function got split up into many functions and the thresholds are getting checked in processDragThresholdEvent(). From what I can tell, this function is not being called everywhere it is needed.

dragDistanceThreshold

For every drag move event, if we are in drag state 2 we should be checking if the distance threshold has been passed. However, processDragMoveEvent() ignores all drag states other than 4. I added the following at the top to try and alleviate this:

//  2 = Pointer being checked if meets drag criteria
if (this.getDragState(pointer) === 2)
{
    this.processDragThresholdEvent(pointer, this.manager.game.loop.now);
}

Since time was not available as a parameter, I looked back at where it can originate form in the old 3.17 and saw that it was coming from the game.loop.now variable so I found a way to access that in the input plugin. Leaving time undefined is okay for a distance threshold but NOT for a time threshold and was causing some weird behavior when a time threshold was set.

dragTimeThreshold

There is no direct drag event that would signal a timeout being over which is what we need for the time threshold to work perfect. Ultimately, if you move the mouse and try to drag it you are creating move events and the change above for the distance threshold will work but it will only trigger once you move the mouse, not exactly when the time threshold is reached.

This doesn't quite match the way 3.17 worked. It would detect the timeout and the draggable image would be tinted red at the exact right moment. You can get this behavior in 3.18+ by simply telling the draggable object to do polling. Just call setPollAlways() (or setPollRate() with some reasonable rate) on the object and then, inside the updatePoll() function, the threshold will get checked on each timeout of the poll and it will trigger without moving the mouse. I updated the documentation for the dragTimeThreshold variable to explain this.

I did also find a bug in how processDragThresholdEvent() was being called inside updatePoll(). The time parameter was not being passed. I fixed this and also guarded against calling it unless the drag state is 2. Here time is a parameter to updatePoll() so I just use that:

if (this.getDragState(pointer) === 2)
{
    this.processDragThresholdEvent(pointer, time);
}

I'm going to package this up in a pull request shortly!

Olliebrown avatar Oct 25 '19 19:10 Olliebrown

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

photonstorm avatar Nov 18 '19 15:11 photonstorm