Multi touch

In the example code ‘multi touch’, if i want to draw an ellipse at the position of my first touch but the second ellipse at a position touch.x(of my second touch)+100. Then how can I get the individual touch.x of all the touches? I want to get the values by storing them in the table using touch.id only, cause otherwise it may give varied results. Atleast that’s what I got.

Here’s something I posted awhile back. I couldn’t find it in the forum so here it is again. Touch the screen with as many fingers as you can and it will keep track of all of them by ID.


supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)

function setup()
    mt={}    -- touch table
end

function draw()
    background(40, 40, 50)
    fontSize(12)
    textMode(CORNER)
    text("ID                           STATE                   X            Y",100,1000)    
    fill(255)
    for z=1,#mt do
        str=string.format("%9d",mt[z].z)
        text(str,60,1000-15*z)    -- touch id

        if mt[z].a==0 then
            str="BEGAN"
        elseif mt[z].a==1 then
            str="MOVING"
        elseif mt[z].a==2 then
            str="ENDED"
        else
            str="UNKNOWN"
        end
        text(str,200,1000-15*z)     -- touch state
        text(mt[z].x,300,1000-15*z)    -- touch x
        text(mt[z].y,350,1000-15*z)    -- touch y
    end     
end

function touched(t)

    for z=1,#mt do    -- check for id
        if t.id==mt[z].z then    -- id already in table
            mt[z]=vec4(t.x,t.y,t.id,t.state) -- update entries             
            return
        end
    end
    -- id doesn't match, add new entry to table
    table.insert(mt,vec4(t.x,t.y,t.id,t.state))
end

Thanks @dave1707.