Nitrous9 Posted August 15, 2016 Share Posted August 15, 2016 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! Quote Link to comment Share on other sites More sharing options...
mattstyles Posted August 19, 2016 Share Posted August 19, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.