Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Two touches = one moving?

edited July 2014 in General Posts: 8

When I touch one area then touch another (2 touches at once)codea recognizes it as one single touch moving, meaning that if the first or second touch is lifted, both are recognized as ended. Help?



  • dave1707dave1707 Mod
    edited July 2014 Posts: 8,781

    @Mac_n_chese Look at this code to see how multiple touches can be kept independent of each other. Touch the screen with several fingers and move them. Lift your finger and retouch to see how the touched are seperate from each other.

    displayMode(FULLSCREEN) function setup() tab={} -- table for touched info, (x,y,id,color) col={} -- table for 10 colors for z=1,10 do -- create 10 random colors c=color(math.random(255),math.random(255),math.random(255)) table.insert(col,c) end end function draw() background(0, 0, 0, 255) for a,b in pairs(tab) do -- use touch info to draw colored circles fill(col[b.w]) -- set color of touched circle ellipse(b.x,b.y, 100, 100) -- draw circle at touched x,y location end end function touched(t) if t.state==BEGAN then -- touch started for a,b in pairs(tab) do -- check if touched id is already in table if then -- id in table, exit touched function return end end -- touch id isn't in the table -- save x,y values, touch id, and a color from 1,10 table.insert(tab,vec4(t.x,t.y,,math.random(10))) end if t.state==MOVING then -- check which touch id is moving for a,b in pairs(tab) do if then -- id matches table b.x=t.x -- update x,y values with new location b.y=t.y end end end if t.state==ENDED then -- check which touch id has ended for a,b in pairs(tab) do if then -- touch id matches table table.remove(tab,a) -- remove it from the table end end end end
  • You never cease to amaze me with your quick and helpful replies @dave1707
    I'll look into it :D

  • dave1707dave1707 Mod
    Posts: 8,781

    @Mac_n_chese I don't have any comments on the code, so if you have any questions, I can add some.

  • edited July 2014 Posts: 8

    I'm understanding most of it, but if I have any questions I'll ask. Thanks ;)

  • Heh, I'm kinda embarrassed, but could you please add comments? XD

  • dave1707dave1707 Mod
    Posts: 8,781

    @Mac_n_chese I added comments to the above code. If you still have questions, just ask.

  • I do have one question..... In the multitouch example ( which I found after posting this discussion) uses something like: tab[]=t. What is it in this example that does the same thing?

  • dave1707dave1707 Mod
    Posts: 8,781

    @Mac_n_chese tab[]=t is just creating a table using the id as the key to a table. What I'm doing is saving the x,y,id,color values as a vec4 in a table. So the uses of the tables are different.

  • Ah I see, thanks again

Sign In or Register to comment.