For a little side project I’m working on a small tapper game to test out my programming skills. The only problem is that you can’t identify a tap (not a beginning of a tap, or end) so you can just press down and earn points like that. Could anyone help?
@Ezekia To identify a continuous tap, when a tap begins, set a variable to true. When the tap ends, set that variable to false. Then in the draw function, if the variable is true, the tap is still happening.
Here’s what I think you’re after.
displayMode(FULLSCREEN)
function setup()
pressed=false
fill(255)
end
function draw()
background(0)
if not pressed then
text("not pressed",WIDTH/2,HEIGHT/2)
else
text("pressing",WIDTH/2,HEIGHT/2)
end
end
function touched(t)
if t.state==BEGAN then
pressed=true
end
if t.state==ENDED then
pressed=false
end
end
And if you want to score only one point per tap, don’t score unless you’ve seen it go back to false. this may require another variable.
Okay, I’ll give it a shot.
The touch
object has a field called tapCount
which might be worth experimenting with to see if that will help you. Other things that are worth considering is to say that a tap occurs if the touch ended within, say, half a second of when it started and didn’t move in between starting and ending.
function touched(t)
if t.state == BEGAN then
maybeTap = true
startTime = ElaspedTime
end
if t.state == MOVING then
maybeTap = false
end
if t.state == ENDED then
if maybeTap and ElapsedTime < startTime + .5 then
isTap = true
else
isTap = false
end
end
end
If you want to handle multiple touches then you’ll need to create a table of touches and store a copy of this data in the table for each touch. I do this in my touch handler class, but that might be overkill for your situation. In case it might be of some use, though, you can find it on github at https://github.com/loopspace/Codea-Library-Base/blob/master/Touch.lua