Using the multi touch demo I’ve inserted a print statement to dump out the value of touch.id
-- Use this function to perform your initial setup
function setup()
print("This example tracks multiple touches and colors them based on their ID")
-- keep track of our touches in this table
touches = {}
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
else
touches[touch.id] = touch
print(touch.id)
end
end
-- This function gets called once every frame
function draw()
background(0, 0, 0, 255)
for k,touch in pairs(touches) do
-- Use the touch id as the random seed
math.randomseed(touch.id)
-- This ensures the same fill color is used for the same id
fill(math.random(255),math.random(255),math.random(255))
-- Draw ellipse at touch position
ellipse(touch.x, touch.y, 100, 100)
end
end
Quite often the same touch.id value appears again after only 2 or 3 touches. Is there a way to prevent this?
I’m building up gestures based on successive touch events and am using the touch.id as the unique identifier for the gesture. If a gesture doesn’t exist with an id the same as any of the touches then create a new gesture. The problem is that if a touch.id is reused to quickly it tries to add it to the existing gesture rather than the new one.
From my experiments with touch.id, the id is valid only as long as the touch lasts. The touch.id can repeat itself over and over again with each touch and as far as I know there isn’t any way to stop it. Using touch.id as an identifier from one touch to another isn’t useful as you’re finding out.
Ok - cheers @dave1707. Moving on then, how is touch.id assigned? Will it ever be less than 5.000e8? By observation I’ve never seen it, but if anyone can shed more light that’d be appreciated (this would allow me to reassign the gesture id to an incremental count starting from 0 and not have to worry until the number of touches exceeded 5e8)
@West You might like to have a look at my touch library. I remember having a few issues with non-uniqueness of touch.id’s. What I ended up doing was distinguishing between active touches and non-active touches. So new touch data was only added to an old touch if the ids matched and the touch was active. If the old touch was non-active (ie had ended) then a new touch was created.
I see touch.id’s in the 4,199,000 to 5,220,000 range, but the majority are in the 216,000,000 to 255,000,000 range. Run this program and keep touching the screen with all your fingers. It will show you the low, high range and the count of the touch.id’s. There are 2 ranges that I’ve been seeing on my iPad1.
supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)
function setup()
l1=100000000
l2=0
h1=800000000
h2=0
lc=0
hc=0
end
function draw()
background(40, 40, 50)
fill(255)
str=string.format("%d -- %d %d",l1,l2,lc)
text(str,300,800)
str=string.format("%d -- %d %d",h1,h2,hc)
text(str,300,600)
end
function touched(t)
if t.id > 100000000 then
hc = hc + 1
if t.id > h2 then
h2 = t.id
end
if t.id < h1 then
h1 = t.id
end
end
if t.id < 100000000 then
lc = lc + 1
if t.id > l2 then
l2 = t.id
end
if t.id < l1 then
l1 = t.id
end
end
end
.@Andrew_Stacey That may have been something that I posted long ago, but I can’t find it either. The forum search function doesn’t work that well and only limits going back 2 pages of searches. So depending on the search, it only goes back a couple of months if that much. There are 54 pages of search information that’s being lost because of the limitation of the search function.
Thanks for the info - @Andrew_Stacey - I’ve had a look at your touch library. I’ve also done a google search on the site and found some of the old discussions, but still don’t know how the value for touch/id is generated
@West According to the Codea-Runtime (file touch.h) the ID is an unsigned int which says that the maximum value is 4,294,967,295 (according to some bloke on the internet).
That’s(4,294,967,295) also the maximum money you can get in many games like temple run, subway surfers…
Using gamecih(on android). There must be a reason.
@West Dunno. I’ve been trying to search the Apple docs since I believe that the id is assigned by iOS, not by Codea (supported by various references to touch->getID), but I can’t find any information on the actual touch data structure.