detecting two finger (or pinch) touch

I am looking for code to ignore a ‘double touch’, or pinch on my android device. I don’t have multi-touch enabled. I have read code snippets to detect this, but I would like to know how can I ignore such events ?

Thanks,
Frank [import]uid: 31039 topic_id: 32178 reply_id: 332178[/import]

Hi Frank,
I’m a bit confused… you don’t have multi-touch enabled, but you want to ensure the user doesn’t try to use it? If you want to explicitly control multi-touch, you actually should enable it… just don’t “handle” it. If the user tries to move/scroll using 2 fingers, then you can detect that and force Corona to ignore it.

If this path seems potentially useful, study the multi-touch documentation and the sample project in Corona’s local directory.

Best regards,
Brent

[import]uid: 9747 topic_id: 32178 reply_id: 128119[/import]

The behavior I am getting is that two finger touch breaks my app, even though I don’t have multi-touch enabled. Incidentally, this only happens on the android devices.

If I turn multitouch on, I figured I might be able to code not to respond to a multitouch.

For example, each touch has its own id. Given this code snippet, how can I prevent multitouch from
executing this function.

local function example(e)

t = e.target

local phase = e.phase

if (e.phase == “began”) then

local parent = t.parent
parent:insert(t)
display.getCurrentStage():setFocus(t, e.id)

tchFlg = tchFlg + 1

if tchFlg > 1 then

tchFlg = 0
— do something here ?
return true
end
… [import]uid: 31039 topic_id: 32178 reply_id: 128215[/import]

Hello again,

Let’s assume that you have one object that senses touch… this could be some object you drag, or even the stage (screen) itself. What I would do is monitor the number of touches that is currently on the object, increasing the count each time a touch “began” occurs, and decreasing each time a touch “ended” occurs.

So, imagine if the user touches one finger down. The count goes up to 1. Then they touch again… it goes up to 2. Then they remove the first finger: count reduces back to 1. Then they touch down 3 more fingers… count goes up to 4. Then they remove all four fingers, count goes to 0. Etc. etc… simple enough counting system.

Now, with this count “attached” as a parameter to the object, you can manage if you handle more than 1 touch (which you don’t want to). I would use this procedure as the first within your touch function:

local object = --a display object, button, whatever  
object.touchCount = 0  
  
local function example( e )  
  
 local t = e.target  
 local phase = e.phase  
  
 if ( phase == "began") then  
 t.touchCount = t.touchCount + 1  
 elseif ( phase == "ended" ) then  
 t.touchCount = t.touchCount - 1  
 end  
  
 if ( t.count \> 1 ) then return --effectively cancel any further processing in this function  
 else  
 --proceed with your touch action  
 end  
  
 return true --prevent touch from extending through to objects behind  
end  

This should prevent any action from occurring on more than one touch… however, it might not solve your issue exactly. Test it out and see if it helps at all.

Best regards,
Brent [import]uid: 9747 topic_id: 32178 reply_id: 128237[/import]

Hi Frank,
I’m a bit confused… you don’t have multi-touch enabled, but you want to ensure the user doesn’t try to use it? If you want to explicitly control multi-touch, you actually should enable it… just don’t “handle” it. If the user tries to move/scroll using 2 fingers, then you can detect that and force Corona to ignore it.

If this path seems potentially useful, study the multi-touch documentation and the sample project in Corona’s local directory.

Best regards,
Brent

[import]uid: 9747 topic_id: 32178 reply_id: 128119[/import]

Brent,

I didn’t think to attach the count to the object. If this does stop any multi-touch (many fingers) actions, It’ll do the job.

Thanks,
Frank [import]uid: 31039 topic_id: 32178 reply_id: 128297[/import]

The behavior I am getting is that two finger touch breaks my app, even though I don’t have multi-touch enabled. Incidentally, this only happens on the android devices.

If I turn multitouch on, I figured I might be able to code not to respond to a multitouch.

For example, each touch has its own id. Given this code snippet, how can I prevent multitouch from
executing this function.

local function example(e)

t = e.target

local phase = e.phase

if (e.phase == “began”) then

local parent = t.parent
parent:insert(t)
display.getCurrentStage():setFocus(t, e.id)

tchFlg = tchFlg + 1

if tchFlg > 1 then

tchFlg = 0
— do something here ?
return true
end
… [import]uid: 31039 topic_id: 32178 reply_id: 128215[/import]

Hello again,

Let’s assume that you have one object that senses touch… this could be some object you drag, or even the stage (screen) itself. What I would do is monitor the number of touches that is currently on the object, increasing the count each time a touch “began” occurs, and decreasing each time a touch “ended” occurs.

So, imagine if the user touches one finger down. The count goes up to 1. Then they touch again… it goes up to 2. Then they remove the first finger: count reduces back to 1. Then they touch down 3 more fingers… count goes up to 4. Then they remove all four fingers, count goes to 0. Etc. etc… simple enough counting system.

Now, with this count “attached” as a parameter to the object, you can manage if you handle more than 1 touch (which you don’t want to). I would use this procedure as the first within your touch function:

local object = --a display object, button, whatever  
object.touchCount = 0  
  
local function example( e )  
  
 local t = e.target  
 local phase = e.phase  
  
 if ( phase == "began") then  
 t.touchCount = t.touchCount + 1  
 elseif ( phase == "ended" ) then  
 t.touchCount = t.touchCount - 1  
 end  
  
 if ( t.count \> 1 ) then return --effectively cancel any further processing in this function  
 else  
 --proceed with your touch action  
 end  
  
 return true --prevent touch from extending through to objects behind  
end  

This should prevent any action from occurring on more than one touch… however, it might not solve your issue exactly. Test it out and see if it helps at all.

Best regards,
Brent [import]uid: 9747 topic_id: 32178 reply_id: 128237[/import]

Brent,

I didn’t think to attach the count to the object. If this does stop any multi-touch (many fingers) actions, It’ll do the job.

Thanks,
Frank [import]uid: 31039 topic_id: 32178 reply_id: 128297[/import]

@Brent,

Unfortunately, I don’t think multitouch is working properly on my Kindle or maybe its Corona. Either way, I am trying to solve this without multitouch activated.It’s is confusing that a multitouch is causing problems even when it is not activated.
Is there a way to detect the second, or third touch etc; from going beyond the ‘begin’ phase of a touch ?

Maybe a way to allow the first touch to complete and block all others. [import]uid: 31039 topic_id: 32178 reply_id: 128549[/import]

Hi Frank,
What exactly happens when you touch down two fingers? Does it crash the app outright? Or something else? Are you using the latest official build of Corona or a daily build? I assume you’ve updated all of your Android software and development tools?
[import]uid: 9747 topic_id: 32178 reply_id: 128552[/import]

latest android os. corona build 2012.894.

I’m moving an image around. one finger, no problem. I check during the move phase to see if I’ve gone past a certain point. If so, I snap the image back to its initial place. Again, no problem with one finger.

When I place two fingers down, the move phase code does not fire. [import]uid: 31039 topic_id: 32178 reply_id: 128554[/import]

Hi Frank,
Can you isolate (somewhat) your touch sense/move code and paste it here? I’d just like to glance at it before determining if this is a Corona bug or not. A sample object which might be touched, its listener, and the touch event function should be sufficient.

Thanks,
Brent [import]uid: 9747 topic_id: 32178 reply_id: 128569[/import]

@Brent,

Unfortunately, I don’t think multitouch is working properly on my Kindle or maybe its Corona. Either way, I am trying to solve this without multitouch activated.It’s is confusing that a multitouch is causing problems even when it is not activated.
Is there a way to detect the second, or third touch etc; from going beyond the ‘begin’ phase of a touch ?

Maybe a way to allow the first touch to complete and block all others. [import]uid: 31039 topic_id: 32178 reply_id: 128549[/import]

Hi Frank,
What exactly happens when you touch down two fingers? Does it crash the app outright? Or something else? Are you using the latest official build of Corona or a daily build? I assume you’ve updated all of your Android software and development tools?
[import]uid: 9747 topic_id: 32178 reply_id: 128552[/import]

latest android os. corona build 2012.894.

I’m moving an image around. one finger, no problem. I check during the move phase to see if I’ve gone past a certain point. If so, I snap the image back to its initial place. Again, no problem with one finger.

When I place two fingers down, the move phase code does not fire. [import]uid: 31039 topic_id: 32178 reply_id: 128554[/import]

Hi Frank,
Can you isolate (somewhat) your touch sense/move code and paste it here? I’d just like to glance at it before determining if this is a Corona bug or not. A sample object which might be touched, its listener, and the touch event function should be sufficient.

Thanks,
Brent [import]uid: 9747 topic_id: 32178 reply_id: 128569[/import]

Hi Brent,
I believe its a transition issue.

It’ll take me sometime to isolate the portion without causing other issues, but the Corona interface/SlideView example program shows the similar problem.

Normal behavior in this program; current image transitions into the next image smoothly after the first image moves ‘about midway’ across the screen.

Here’s the problem I share with this program with a two finger touch,;

moving current image midway across the screen leaves both current image and next image at that location. no complete transition.

Three or more fingers results in no movement at all.
Thanks,
Frank [import]uid: 31039 topic_id: 32178 reply_id: 128671[/import]

Hi Frank,
I wonder if you could download and test the “parallax” module tutorial that I wrote about recently, on your Kindle, and see how it behaves. This uses basic touch/drag sensing and might help determine if your issue is a Corona issue/bug, a Kindle device issue, or something with the SlideView module.

The parallax module should be run without multi-touch enabled… of course, I haven’t tested it with multi-touch, so I have no idea how it might function in that case!

http://www.coronalabs.com/blog/2012/10/16/parallax-simplified/

Thanks,
Brent
[import]uid: 9747 topic_id: 32178 reply_id: 128680[/import]

Hi Brent,

Works great in both modes; multitouch activated and not.

I noticed there aren’t any ‘transition’ statements in the code.

Three or more finger touch, no movement.

Thanks,
Frank [import]uid: 31039 topic_id: 32178 reply_id: 128686[/import]