HI guys, I’m making a line just like fruit ninja effect when you touch the screen.
I have this effect in a module called lineDrawing.lua
I also have a file called level1.lua that has been setup with storyboard. In level1.lua I call the startListener() function from lineDrawing to start the fruitninja effect.
My problem is that my display.newLines from lineDrawing.lua never get released from memory even though I removed and nilled them because they are never inserted into the self.view group from level1.lua … I don’t want to insert the lineDrawing code on every level. Is there a correct way to release this memory and still have my lineDrawing module?
thanks a lot!
[code]
–lineDrawing.lua
local LD ={}
local bx, by=0, 0 – Create our variables for drawing the line
local lines={}
local function fruitNinja(event)
if “began”==event.phase then
bx, by=event.x, event.y
elseif “moved”==event.phase then
for i=#lines+1, #lines+1 do
lines[i]=display.newLine(bx, by, event.x, event.y)
lines[i].width=10
local myLine=lines[i]
local function erase(obj)
display.remove(obj) – not sure if this is ok
obj=nil
end
lines[i].transition=transition.to(myLine, {alpha=0, width=1, time=300, onComplete=erase}) – The key transition
bx, by=event.x, event.y
end
elseif “ended”==event.phase then
end
end
local startListener = function()
Runtime:addEventListener(“touch”, fruitNinja)
end
LD.startListeners = startListeners
local removeListener = function ()
Runtime:removeEventListener(“touch”, fruitNinja)
end
LD.removeListeners = removeListeners
return LD
[/code] [import]uid: 74667 topic_id: 35817 reply_id: 335817[/import]