2013-05-18 19 views
2

안녕하세요이 코드를 사용하여 장면에서 내 개체를 움직이게 (애니메이션 처리)합니다. 하지만 메모리가 누수되어 응답하지 않습니다.corona sdk에서 오브젝트를 이동하는 방법은 무엇입니까?

//transition back 
local function goBack() 
    transition.to (wall2, { time = 10000, x = 100, y = 310, onComplete = startTransition}) 
    transition.to (wall, { time = 10000, x = 700, y = 200, onComplete = startTransition}) 
    transition.to (gate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition}) 
    transition.to (stargate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition}) 
end 

//transition start 
function startTransition() 
    transition.to (wall2, { time = 10000, x = 700, y = 310, onComplete = goBack}) 
    transition.to (wall, { time = 10000, x = 100, y = 200, onComplete = goBack}) 
    transition.to (gate_a, { time = 10000, x = 700, y = 255, onComplete = goBack}) 
    transition.to (stargate_a, { time =10000, x = 700, y = 255, onComplete = goBack}) 
end 

startTransition() 

메모리 누수없이 개체를 올바르게 이동하려면 어떻게해야합니까?

답변

8

과 같이 수행하지 :

//transition back 
local function goBack() 
    transition.to (wall2, { time = 10000, x = 100, y = 310}) 
    transition.to (wall, { time = 10000, x = 700, y = 200}) 
    transition.to (gate_a, { time = 10000, x = 100, y = 255}) 
    transition.to (stargate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition}) 
end 

//transition start 
function startTransition() 
    transition.to (wall2, { time = 10000, x = 700, y = 310}) 
    transition.to (wall, { time = 10000, x = 100, y = 200}) 
    transition.to (gate_a, { time = 10000, x = 700, y = 255}) 
    transition.to (stargate_a, { time =10000, x = 700, y = 255, onComplete = goBack}) 
end 

startTransition() 

이후 모든 시간의 기간은 동일합니다, 모든 전환에 onComlpete를 호출 할 필요합니다.


그리고 필요한 경우 함수 내의 전환을 취소 할 수 있습니다. 이를 위해 전환에 이름을 지정하고 전환이 아직 진행 중인지 확인한 다음 중단하십시오. 예를 보여 드리겠습니다. 이것은 필수 아니지만, 여전히 위의 코드를 실행 한 후 기억 상실을 앓고 있다면, 당신은 그것을 사용할 수 있습니다 :

local trans_1,trans_2; 
local function goBack() 
    if(trans_1)then transition.cancel(trans_1) end -- to cancel an existing transition 
    trans_2 = transition.to (wall2, { time = 10000, x = 100, y = 310}) 
end 

function startTransition() 
    if(trans_2)then transition.cancel(trans_2) end -- to cancel an existing transition 
    trans_1 = transition.to (wall2, { time = 10000, x = 700, y = 310}) 
end 

startTransition() 

코딩 계속 .............

관련 문제