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()
    x=0
    y=0
end

function draw()
    background(0,0,0)
    fill(255,255,255)
    ellipse(CurrentTouch.x,CurrentTouch.y)
 end

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

Tagged:

Comments

  • 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: 7,604

    @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 id=t.id pos=vec2(t.x,t.y) end if t.state==MOVING and id==t.id then pos=vec2(t.x,t.y) end if t.state==ENDED and id==t.id 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: 7,604

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

Sign In or Register to comment.