Howdy, Stranger!

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

Touch ID

edited August 2014 in Questions Posts: 145

How can I track the first touch on a screen. For example I have this program:

function setup()

function draw()

However, it fails when another touch hits the screen. How can I only follow the first touch?



  • Posts: 1,976

    Try looking at the Multitouch example. You usually want to avoid CurrentTouch at all costs, because it brings up problems like this later on.

  • dave1707dave1707 Mod
    edited August 2014 Posts: 8,720

    @austinmccoy Try this example. Drag the sprite around the screen while moving other fingers on the screen.

    function setup() id=0 pos=vec2(WIDTH/2,HEIGHT/2) end function draw() background(40, 40, 50) if pos.x+pos.y>0 then sprite("Planet Cute:Character Boy",pos.x,pos.y) end end function touched(t) if t.state==BEGAN and id==0 then pos=vec2(t.x,t.y) end if t.state==MOVING and then pos=vec2(t.x,t.y) end if t.state==ENDED and then id=0 end end
  • Thanks!

  • In your first if then loop in the touched function where you save the vector, I think you meant pos=vec2(t.x,t.y)

  • dave1707dave1707 Mod
    Posts: 8,720

    @austinmccoy You're correct. I corrected it in the above code.

Sign In or Register to comment.