JeZxLee

Need Android Muti-Touch Example...

Recommended Posts

Hi,

I want to add support for multi-touch on Android devices today.
I just need to detect only two simultaneous taps (one on directional pad & one on button)

Is there some example code I can look at to learn the above?
Thanks!

JeZxLee

Share this post


Link to post
Share on other sites

It just works. If you had a pointerdown callback on your directional pad, and a pointerdown callback on your buttons, then they'll both get called even if you have the screen held down elsewhere.

If you have just a pointerdown on the top level of interactionManager, then look within the event.data object and you'll see all of the data that exists for that event, including information to distinguish between different presses

Share this post


Link to post
Share on other sites

Hi,

Do I need to use two "pointerdown" functions to register two fingers on Android screen?

renderer.plugins.interaction.on('pointerdown', function(event) {
	MouseCoordinates = event.data.global;
	TouchScreen = true;
});

renderer.plugins.interaction.on('pointerup', function(event) {
	MouseCoordinates = event.data.global;
	TouchScreen = false;
});

Thanks!

JeZxLee

Share this post


Link to post
Share on other sites

For different fingers, "event.data" is different. Look at it closely. Unfortunately, I didnt work with this feature, @themoonrat can help you but only if you investigate what is stored in event.data first! Don't ask him if you havent tried to extract info from "event.data", he's very busy :)

Share this post


Link to post
Share on other sites

Probably you'll have an easier time if you use separate event handlers for pad and button. Like this for example:

pad.interactive = true;
pad.on('pointerdown', function (event) {
    // do stuff when press down on direction pad
});
pad.on('pointerup', function (event) {
    // do stuff when press is released on direction pad
});

button.interactive = true;
button.on('pointerdown', function () {
   // do stuff when button is clicked 
});

EDIT: Also the examples for Click and Interactivity are good reference for this - that's where I learned above technique..

Share this post


Link to post
Share on other sites

After 5 hours I almost got it...
Can someone look at my code and help out?

Code is downloadable on the title screen at below URL link in signature...

JeZxLee

Share this post


Link to post
Share on other sites

It seems like you have 6 buttons (4 arrow buttons and 2 round buttons). So I think it's easiest and most straightforward to approach it like the interactivity example and give each of the 6 buttons its own event handlers. And if you need to know when multiple buttons are being pressed at once (instead of handling each button separately) then you can set a flag for each button for instance to track whether it's being pressed down or not.

EDIT: Note: The example is different since each button is handled by same functions but you can adapt it to use different function for each button like I showed above.

Share this post


Link to post
Share on other sites

My goal is to support touch and drag on the directional pad (4 buttons)
while supporting simultaneous touch of either action button(2 buttons).

Little tired, need to rest - I'll try this again tonight...

JeZxLee

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.