Game Development Reference
In-Depth Information
Drawing with Touch
I previously discussed how you can move the display object based on the touch point. If you create
an array of touch points, you can render them to generate interesting results. Here's an example:
points = {}
index = 0
maxPts = 99
function setup()
watch("index")
end
function touched(touch)
index = index + 1
if index > maxPts then
index = maxPts
table.remove(points, 1)
end
table.insert(points, touch)
end
function draw()
background(40,40,50)
strokeWidth(3)
lineCapMode(ROUND)
if index > 1 then
ptx, pty = points[1].x, points[1].y
for i=2, index do
sx, sy = points[i].x, points[i].y
line(ptx,pty, sx, sy)
ptx, pty = sx, sy
end
end
end
For some variety, you can also play with maxPts variable and see the results.
Note To watch a variable, simply use the function watch but remember to enclose the variable
name in quotes for it to work. If the variable is a table, it displays as Table and an address to the
memory, while the internal objects created by Codea can be watched without specifying the individual
components, like watch("Gravity") can be used to watch all of the three axis data instead of each
individual axis as watch("Gravity.x") , watch("Gravity.y") and watch("Gravity.z")
 
 
Search WWH ::




Custom Search