2014-07-04 4 views
0

일부 직사각형을 생성하고 각 직사각형이 화면 아래로 이동하도록 전환됩니다. 트랜잭션이 완료된 메모리에서 해당 직사각형을 제거하려고합니다 (화면 아래로 이동하여 더 이상 화면에 표시되지 않는 직사각형을 의미 함). 그러나 가시적 인 (새로 생성 된) 사각형은 제거됩니다.전환시 개체 제거 완료

여기의 onComplete 리스너가 이미 전환되고 있던 객체를 받아 내 코드

--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) 

답변

2

입니다. 그래서, 당신은 그것을 전달할 필요가 없습니다.

그냥 아래, onComplete를 = removeRect을 위해 transition.to을 변경

transition.to(rects[numRect], {time = 9000, y = display.contentHeight + 100, 
     onComplete = removeRect })