what about this for currentTouch demo:
--# Main
-- CurrentTouch demo00
function setup()
info = [[
CurrentTouch gives information on the most recent touch that occurred
CurrentTouch.state can have the following values:
BEGAN, MOVING, ENDED, CANCELLED
The finger position is
CurrentTouch.x
CurrentTouch.y
The last position of this finger is
CurrentTouch.prevX
CurrentTouch.prevY
The difference current position minus last one is
CurrentTouch.deltaX
CurrentTouch.deltaY
If you tap on the screen without moving the finger too much, you get this count:
CurrentTouch.tapCount
CurrentTouch is always available, but is updated only when you start or move or end a touch
Before any touch has occured, it is in CANCELLED state
It has a defined id field, but its value is always 0
It is ok with 1 touch only, but it gets messy if you put 2 or more fingers on the screen
]]
end
-- a table to convert touch state (0,1,...) into a readable string
local states = {}
states[BEGAN] = "BEGAN"
states[MOVING] = "MOVING"
states[ENDED] = "ENDED"
states[CANCELLED] = "CANCELLED"
-- returns a string with all touch fields
function touchToString(name,t)
local str = {
name,
"id = ",
"state = ",
"x = ",
"y = ",
"deltaX = ",
"deltaY = ",
"prevX = ",
"prevY = ",
"tapCount = ",
}
if t then
str = {
"",
tostring(CurrentTouch.id),
states[CurrentTouch.state],
tostring(CurrentTouch.x),
tostring(CurrentTouch.y),
tostring(CurrentTouch.deltaX),
tostring(CurrentTouch.deltaY),
tostring(CurrentTouch.prevX),
tostring(CurrentTouch.prevY),
tostring(CurrentTouch.tapCount),
}
end
str = table.concat(str,"\
")
return str
end
function drawTouchInfo(name,touch,x,y)
-- draw the touch info
fill(57, 57, 57, 255) -- set color for text
fontSize(20) -- set font size
font("ArialMT")
textMode(CORNER)
textAlign(RIGHT) -- align text to the left
titles = touchToString(name)
text(titles,x-10-(textSize(titles)),y) -- draw text on screen
textAlign(LEFT) -- align text to the right
values = touchToString(name,touch)
text(values,x,y) -- draw text on screen
end
function draw()
noStroke()
background(178, 178, 178, 255)
-- draw the touch
local t = CurrentTouch -- a copy
fill(255, 190, 0, 255) -- button color
ellipseMode(RADIUS)
ellipse(t.x,t.y,50)
-- draw the CurrentTouch info
drawTouchInfo("CurrentTouch : ", CurrentTouch, WIDTH/2, HEIGHT-250)
textMode(CENTER)
fontSize(17)
font("Arial-ItalicMT")
text(info, WIDTH/2, 250)
end