Hey, i don’t understand how to use multitouches properly, ive looked at the examples and searched the forum but im even more confused now.
Heres an example:
I’m trying to make two squares, when touched, follow the individual touch and change color, then change back when the touch ends.
Not sure if this is how to paste my code but here goes
function setup()
touches = {}
b = vec2(100,100) --blue rect x,y
bcolor = color(0, 0, 100)
r = vec2(500,100) --red rect x,y
rcolor = color(100, 0, 0)
end
function draw()
for i,touch in pairs(touches) do
if touch.x > b.x - 100 and touch.x < b.x + 100 and
touch.y > b.y - 100 and touch.y < b.y + 100 then
b.x = touch.x
b.y = touch.y
bcolor = color(0, 0, 255)
else
bcolor = color(0, 0, 100)
end
if touch.x > r.x - 100 and touch.x < r.x + 100 and
touch.y > r.y - 100 and touch.y < r.y + 100 then
r.x = touch.x
r.y = touch.y
rcolor = color(255, 0, 0)
else
rcolor = color(100, 0, 0)
end
end
background()
rectMode(CENTER)
fill(bcolor)
rect(b.x,b.y,200,200)
fill(rcolor)
rect(r.x,r.y,200,200)
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
else
touches[touch.id] = touch
end
end