Multitouch detection : count how many fingers

Hi,
Is there a way to know how many fingers are touching the screen?
For example, if I put 3 fingers, it prints 3 until they leave the screen. Then it prints 0 if I leave all fingers in same time or after leaving fingers one after the other : 2,1,0.

I wanted to use the event.id as index in a table but it’s a userdata. I don’t know what to do with it.
Somebody can help?
Thanks in advance,
Walter [import]uid: 107239 topic_id: 23915 reply_id: 323915[/import]

Thank you for your code, i’ll try it but for what the id property and system.activate(“multitouch”) so? We don’t need them? [import]uid: 107239 topic_id: 23915 reply_id: 96398[/import]

[lua]system.activate(“multitouch”)
local text = display.newText("", 0, 0, native.systemFont, 12)

count = 0
function touch(event)
if event.phase == “begin” then
count = count + 1
else if event.phase == “ended” then
count = count - 1
end
text.text = count
end

Runtime:addEventListener(“touch”, touch)[/lua] [import]uid: 79135 topic_id: 23915 reply_id: 96359[/import]

I haven’t tried an app with multitouch (testing on mac atm) so don’t know how the ids work really.

Oh yes. You are right sorry. I will edit my code.

I think for the event.id’s: the first touch is event 1, the second is event 2 and so on. [import]uid: 79135 topic_id: 23915 reply_id: 96399[/import]

The event.id is userdata type, i don’t know how i could use it but the most boring is you can’t test and understand these kind of things directly on the simulator. By the way i don’t need for now, i just need your sample, thank you :wink:

PS: it’s “began” instead of “begin”, and “elseif” instead of “else if” :wink: [import]uid: 107239 topic_id: 23915 reply_id: 96405[/import]

i submitted a library module to help out with multi-touch apps. the example which is included already does most of what you want (tracking the number of touches on an object). You would just need to print the number on the screen. :slight_smile:

http://developer.anscamobile.com/code/dmc-lib-touch-manager

cheers,
dmc [import]uid: 74908 topic_id: 23915 reply_id: 109937[/import]

Thanks it will certainly very useful for all newbies first and others too [import]uid: 107239 topic_id: 23915 reply_id: 109973[/import]

waltsir, even though the event.id is userdata, it has a value which can be used as a unique identifier for a touch. I use it as a string table key and it works fine. [import]uid: 22076 topic_id: 23915 reply_id: 109996[/import]