android - How to move object in corona sdk? -


hey using code move (animate) objects on scene leaks memory , stop responding.

//transition 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() 

how move objects without leaking memory?

do this:

//transition 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() 

since time duration same, no need call oncomlpete on transitions.


and if need, can cancel transitions inside functions. that, assign name transition, check whether still in progres, stop it. i'll show example. not mandatory, if still suffering memory loss after implementing above code, can use it.:

local trans_1,trans_2; local function goback( )     if(trans_1)then transition.cancel(trans_1) end   -- cancel 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 -- cancel existing transition     trans_1 = transition.to ( wall2, { time = 10000, x = 700, y = 310}) end  starttransition( ) 

keep coding............. 😃


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -