Is there a way to detect long presses in Phaser 3? I believe it was possible to count the duration of pointer down in Phaser 2, but I am having trouble finding an equivalent function in 3.
Pointer has downTime and upTime properties that may be useful. According to the docs, they’re used for dragging but I imagine you can use them to test if the press was longer than a chosen threshold.
I’m not quite sure how to use downTime and upTime effectively. The first downtime value appears to be set by the amount of time the game starts and when the pointerdown event is set. I thought this would be set by the length of the pointer down event
Yeah, downTime and upTime get set to the time at which the pointer was pressed down and released.
I think you could do something along the lines of checking the pointer.downTime in your update method and comparing it to the time parameter passed to the scene’s update method (https://github.com/photonstorm/phaser/blob/v3.14.0/src/scene/Systems.js#L355).
Keep in mind though that downTime doesn’t get reset when the pointer is released, so there may be better options out there.
You can in addition to calculate the downtime by doing (currentTime- pointer.downTime) also check if pointer.upTime is lower than pointer.downTime - that would means it is still pressed.
(Because if the pointer has a down time more recent than the uptime, it is still beeing pressed down)