Jump to content

How To Detect Pressing & Holding Screen On Android?


JeZxLee
 Share

Recommended Posts

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) );

CobraEngine100Percent-01.thumb.png.fb1cf4ec2e9f743ecd0e9a72fa6a95f2.png

Link to comment
Share on other sites

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...

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...