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?
Try looking at the Multitouch example. You usually want to avoid CurrentTouch at all costs, because it brings up problems like this later on.
@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
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)
@austinmccoy You’re correct. I corrected it in the above code.