Hi All,
My latest project involves the development of a system to store and track the times that a user has touched the screen.
I ran in to an issue with the storing of the touch data - the time began and the time ended. I’ve found a solution to my problem (just insert the times into a table and if it’s odd its when the touch began, if it’s even, it’s when the touch ended), however it is very crude and will not work for an larger version of the project.
Here is my code:
function setup()
input = {}
numTouches = 0
isTouched = false
end
-- This function gets called once every frame
function draw()
background(255, 255, 255, 255)
stroke(0, 0, 0, 255)
lineCapMode(ROUND)
strokeWidth(10)
if isTouched then
if numTouches == 0 then
print("touch ended")
table.insert(input, ElapsedTime)
isTouched = false
end
else
if numTouches > 0 then
print("touch began")
table.insert(input, ElapsedTime)
isTouched = true
end
end
local m = 100
for i = 1, math.ceil(#input / 2) do
local began = ElapsedTime - input[i * 2 - 1]
local ended = ElapsedTime - (input[i * 2] or ElapsedTime)
line(WIDTH * .75 - began * m, HEIGHT / 2, WIDTH * .75 - ended * m, HEIGHT / 2)
end
strokeWidth(2)
line(WIDTH * .75, 0, WIDTH * .75, HEIGHT )
end
function touched(touch)
if touch.state == BEGAN then
numTouches = numTouches + 1
elseif touch.state == ENDED then
numTouches = numTouches - 1
end
end
The specifically problematic part is the loop for i = 1, math.ceil(#input / 2) do
Any suggestions on how to refine this? Preferably on the structure of the data?