Hi everybody. I wrote some basic kinetic scrolling code, but have a strange problem with removing table records.
I have to record all movements to check what was the last direction before finger release. Everything works ok, but when I try to clean path table after scroll was done, I have an errors. I tried table.remove with for loop, path=nil, but nothing helps.
How to clean this table properly?
[lua]display.setStatusBar( display.HiddenStatusBar )
system.activate( “multitouch” )
local cw, ch = display.contentWidth, display.contentHeight
local pic = display.newImage(“Caspar.jpg”, 0,0, false)
pic.x = cw/2
pic.y = ch/2
local path = {}
local i =1
function kinetic (e)
if e.phase == “began” then
storeX = e.x-pic.x
storeY = e.y-pic.y
eventTime = e.time
elseif e.phase == “moved” then
pic.x = e.x - storeX
pic.y = e.y - storeY
path[i] = {}
path[i].x = e.x
path[i].y = e.y
path[i].timer = e.time
i=i+1
elseif e.phase == “ended” then
local totalTime = path[#path].timer - path[#path-4].timer
local pathX = path[#path].x - path[#path-4].x
local pathY = path[#path].y - path[#path-4].y
local velocityX = math.abs (pathX/totalTime)*2
local velocityY = math.abs (pathY/totalTime)*2
finalX = e.x + pathX*velocityX - storeX
finalY = e.y + pathY*velocityY - storeY
transition.to (pic, {transition=easing.outExpo, y=finalY, x=finalX})
end
end
pic:addEventListener (“touch”, kinetic)[/lua] [import]uid: 117007 topic_id: 23902 reply_id: 323902[/import]