I’m trying to count the number of concurrent touches. I’ve added the line
print(table.getn(touches))
to the multitouch example but it doesn’t give the results I expect. Am I missing something simple here?
Mark
-- 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
end
end
-- This function gets called once every frame
function draw()
background(0, 0, 0, 255)
print(table.getn(touches))
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