Lua 在转换完成时删除对象
我正在生成一些矩形,每个矩形都被转换为在屏幕上向下移动。我试图从内存中删除那些事务已完成的矩形(意味着在屏幕上向下移动并且在屏幕上不再可见的矩形)。但是,可见(新生成的)矩形将被删除 这是我的密码Lua 在转换完成时删除对象,lua,coronasdk,Lua,Coronasdk,我正在生成一些矩形,每个矩形都被转换为在屏幕上向下移动。我试图从内存中删除那些事务已完成的矩形(意味着在屏幕上向下移动并且在屏幕上不再可见的矩形)。但是,可见(新生成的)矩形将被删除 这是我的密码 --table to hold dynamically created rectangles local rects={} --used as index for table local numRect=0 local function removeRect( obj ) local rec
--table to hold dynamically created rectangles
local rects={}
--used as index for table
local numRect=0
local function removeRect( obj )
local rectid = obj.id
obj:removeSelf( )
rects[rectid] = nil
end
--function for spawning rectangles
local function spawnRect()
numRect = numRect + 1
rects[numRect] = display.newRect( display.contentWidth/2, 100, 100, 100)
rects[numRect]:setFillColor( 1,1,1 )
rects[numRect].id = numRect
transition.to( rects[numRect], {time = 9000, y = display.contentHeight + 100,
onComplete = function()
removeRect(rects[numRect])
end
} )
end
timer.performWithDelay( 1000, spawnRect, -1 )
onComplete侦听器已接收正在转换的对象。所以,你不需要通过考试 只需将transition.to更改为onComplete=RemoveECT,如下所示:
transition.to( rects[numRect], {time = 9000, y = display.contentHeight + 100,
onComplete = removeRect } )