Jump to content

Best way to detect Double-Tap-Hold event on mobile?


Nitrous9
 Share

Recommended Posts

Hey guys!

I'm working on adding a new ability to a game I'm working on.  And I want to be able to activate it on mobile by double tapping the screen and hold to keep it active, then de-activate it when finger is released.   Has anyone else solved this problem or have any suggestions on the best approach?

 

Thanks!

Link to comment
Share on other sites

You just need to hook up a couple of timers to touch events. Keep track of the last release time and of the current press time. When the current press time is above a certain threshold check your last release time, if this is also within a certain threshold then you have your awkward double-tap-hold event.

Use performance.now or Date.now, either will be granular enough for you.

The tricky part is getting the current press time. I'd suggest start emitting events when the touchdown is detected and stop when a touchup is detected, have the event emit the current time minus the start time and you get the delta of the press time, have something listen for that event and check the delta against your defined threshold, cross-check with the last touchup and you'll have all the data you need to trigger a double-tap-hold event. Using streams to hold that data would be best, but its not strictly necessary, stick state wherever it makes sense to you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...