Hi!
I am searching for a code which says that if you are using two fingers then… Something is happening
There is a multi touch demo program in the examples provided with Codea
Here is a program that says “2 Fingers Touching!” when the user is touching the screen with two fingers. It also displays in the top left corner how many fingers are touching the screen. If you don’t understand something in the code, I recommend looking it up because it’s very important to know how your code works.
-- Use this function to perform your initial setup
function setup()
print("Touch the screen with two fingers")
touchAmount = 0
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
fill(255)
fontSize(40)
if touchAmount == 2 then -- If the amount of touches is two...
text("Two Fingers Touching!",WIDTH/2,HEIGHT/2)
end
text("Fingers: "..touchAmount,100,HEIGHT-100)
end
function touched(touch)
if touch.state == ENDED then
touchAmount = touchAmount - 1
elseif touch.state == BEGAN then
touchAmount = touchAmount + 1
end
end
Here’s some code that will draw a random colored line between your 2 fingers as you move them around the screen.
displayMode(FULLSCREEN)
function setup()
tab={}
stroke(255)
strokeWidth(2)
background(0)
backingMode(RETAINED)
end
function draw()
cnt=0
for a,b in pairs(tab) do
cnt=cnt+1
if cnt==1 then
x1,y1=b.x,b.y
end
if cnt==2 then
stroke(math.random(255),math.random(255),math.random(255))
line(x1,y1,b.x,b.y)
end
end
end
function touched(t)
if t.state==BEGAN then
tab[t.id]=vec2(t.x,t.y)
end
if t.state==MOVING then
tab[t.id]=vec2(t.x,t.y)
end
if t.state==ENDED then
tab[t.id]=nil
end
end