Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDuration for active pointer does not work properly #4444

Closed
plazicx opened this issue Mar 25, 2019 · 2 comments
Closed

getDuration for active pointer does not work properly #4444

plazicx opened this issue Mar 25, 2019 · 2 comments

Comments

@plazicx
Copy link

plazicx commented Mar 25, 2019

Version

  • Phaser Version: 3.16.2
  • Operating system: W10
  • Browser: Chrome 73.0.3683.86 (Official Build) (64-bit),
    Firefox 65.0.2 (64 bit)

Description

I want to measure for how long the left mouse button is pressed - the command
this.input.activePointer.getDuration();
returns 0 UNTIL there is some other event on the input (like move) - then it indeed returns the time since
the left mouse button was pressed.

combination of
this.input.activePointer.downTime - this.time.now
works fine.

As far as I understand from the code in the /src/input/Pointer.js

getDuration: function ()
{
if (this.isDown)
{
return (this.time - this.downTime);
}
else
{
return (this.upTime - this.downTime);
}
},

the problem is that this.time returns Time when this Pointer was most recently updated by the Game step.
so if I press the left button and not move the mouse that time will be exactly the same as this.downTime
hence the duration reported will be 0.
(obviously on my laptop the Pointer is not considered updated by game step if it at least does not move so measuring duration of button press in this way does not work properly)

Example Test Code

if (this.input.activePointer.leftButtonDown()){
let time2 = this.time.now;
let time3 = this.input.activePointer.downTime;
let time = time2-time3;
time=this.input.activePointer.getDuration();

Additional Information

@plazicx
Copy link
Author

plazicx commented Mar 25, 2019

OK now I found this
https://rexrainbow.github.io/phaser3-rex-notes/docs/site/touchevents/
so it is actually get drag duration. Comments in the files should be modified a bit to reflect that.

@photonstorm
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants