JeZxLee Posted August 13, 2017 Share Posted August 13, 2017 Hi, We got the on-screen gamepad working now on Android. The only problem is we don't know how to register when user presses and holds finger on the screen? Currently if user presses and holds finger on screen it only registers one input event and is not constant? Any help would be appreciated, thanks... (project URL in signature has been updated with new build) renderer.plugins.interaction.on('pointerdown', function(event) { MouseCoordinates = event.data.global; }); MouseX = Math.floor( MouseCoordinates.x / (widthScale) ); MouseY = Math.floor( MouseCoordinates.y / (heightScale) ); Quote Link to comment Share on other sites More sharing options...
themoonrat Posted August 13, 2017 Share Posted August 13, 2017 When the user presses down (pointerdown), you start a timeout. If the user releases (pointerup), you clear that timeout If the timeout completes, they've held down the screen Taz 1 Quote Link to comment Share on other sites More sharing options...
Taz Posted August 13, 2017 Share Posted August 13, 2017 There's four events to catch: 'pointerdown', 'pointerup', 'pointerupoutside', and 'pointermove'. So on 'pointerdown' you can set a flag to true and then set the flag to false on the other events (or maybe not on 'pointermove' if you don't want dragging to cancel it). This will work if you want to be able to check the flag each frame and update accordingly. Or if you want to fire an event repeatedly while user is pressing and holding, then you can for example call setInterval in 'pointerdown' handler to repeatedly call function as often as you'd like. Just save the return value from setInterval so that you can cancel the timer in other event handlers using clearInterval(returnValueFromSetInterval). Also you can pass params like position or the whole event object if you want. EDIT: I was thinking you wanted to repeat the event while pressing, but if you just want one event after pressing for a bit then @themoonrat has you answered. Also maybe Hammer.js can help in that case... Quote Link to comment Share on other sites More sharing options...
JeZxLee Posted August 13, 2017 Author Share Posted August 13, 2017 That makes some sense, thank you... JeZxLee 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.