Hi !
I’m totally new to codea (and to prog globally), so I have a problem which might seem stupid but here it is :
I would like an action to be made if someone touch the screen in a particular spot and to stop when he releases his finger.
At the moment I’m using :
if CurrentTouch.state==MOVING then
print("pressed")
end
So when I move my finger around it works, but I’d like it to work with a still finger in a particular spot (a button for example)…
If anyone can help me with this, that’d be great !!
Thanks
function setup()
str=""
end
function draw()
background(40, 40, 50)
fill(255)
text(str,WIDTH/2,HEIGHT-100)
rect(200,300,100,50)
fill(255,0,0)
text("Press",250,325)
end
function touched(t)
if t.state==BEGAN then
if t.x>200 and t.x<300 and t.y>300 and t.y<350 then
str="Button pressed"
end
end
if t.state==ENDED then
str=""
end
end
@Toufalex Here’s an example that allows you press or to slide your finger across the button.
function setup()
str=""
end
function draw()
background(40, 40, 50)
fill(255)
text(str,WIDTH/2,HEIGHT-100)
rect(200,300,100,50)
fill(255,0,0)
text("Press",250,325)
end
function touched(t)
if t.state==BEGAN or t.state==MOVING then
if t.x>200 and t.x<300 and t.y>300 and t.y<350 then
str="Button pressed"
else
str=""
end
end
if t.state==ENDED then
str=""
end
end