[Solved] Memory usage

Hi,

I use the following code to move 2 sprites left and right continuesly:

local function WaveAnim()  
 local WaveRight = function()  
 transition.to( wave1, {time=10000, x=1, onComplete=WaveAnim})  
 transition.to( wave2, {time=10000, x=1620, onComplete=WaveAnim})  
 end  
  
transition.to( wave1, {time=10000, x=1620, onComplete=WaveRight})  
transition.to( wave2, {time=10000, x=1, onComplete=WaveRight})  
  
end  
  
WaveAnim()  

After a while, Memory usage goes through the roof, and simulator stops responding.

What am i doing wrong?

BTW: If i uncomment ‘WaveAnim()’ memory usage is fine.

[import]uid: 50459 topic_id: 14330 reply_id: 314330[/import]

Any animation will increase memory some but personally the code looks fine to me (im still a noob though so dont take it as gospel).

My only concern would be the size of the image you are moving. I remember seeing an article about what you need to have in your PNG files (settings etc) and if you have alot of alpha(transparency) in it, it will require alot more cpu/memory to move around.

Hopefully a more senior member will chime in and give you a little more concrete help but it might give you something to test. Replace your images and a solid color replacement and see if it moves smoothly etc.

Regards,

Adrian [import]uid: 83851 topic_id: 14330 reply_id: 52935[/import]

@rmbsoft,
my first post after the short, really short break.

  1. What you are doing wrong in your code is called recursion, that is causing a memory leak / stack overflow.

now to achieve what you are after, I had a post on howto.oz-apps.com that you can find here this is about pulsating, you can apply the same theories to your code to move it left to right continuously. Hope it is explained well and you do get something from that.

If you like it, leave a note there stating that you liked it and it did help you.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14330 reply_id: 52992[/import]

Would this get around that issue? Both animations technically finish at the same time so you only need to call the functions from the one transition. In theory it should work… practically it might not.

[lua]local function waveAnimLeft()
transition.to( wave1, {time=10000, x=1620})
transition.to( wave2, {time=10000, x=1,onComplete=waveAnimRight})
end

local function waveAnimRight()
transition.to( wave1, {time=10000, x=1})
transition.to( wave2, {time=10000, x=1620,onComplete=waveAnimLeft})
end

waveAnimLeft() [/lua] [import]uid: 83851 topic_id: 14330 reply_id: 53023[/import]

@maletta, thanks for your suggestion. I used your idea removing the onComplete event of the second transition to get this working.

@jayantv, thanks for the help, very informative article.

You might want to change the code errors (tranistion.to instead of transition.to)

The sample at the bottom only fades out, i fixed it by moving:

tranistion.to(rect,{time=1000,alpha=0, onComplete = function1})

to the bottom of the code. Then it works properly.

local function1, function2  
local trans  
   
local rect = display.newRect(10,10,300,40)  
 rect:setFillColor(255,255,255)  
   
function function1(e)  
 trans = transition.to(rect,{time=1000,alpha=1, onComplete=function2})  
end  
   
function function2(e)  
 trans = transition.to(rect,{time=1000,alpha=0, onComplete=function1})  
end  
  
transition.to(rect,{time=1000,alpha=0, onComplete = function1})  
  

So the solution for me was:

local function1, function2  
   
function function1(e)  
 -- Left  
 transition.to( wave1, {time=10000, x=1, onComplete=function2})  
  
 transition.to( wave2, {time=10000, x=1620})  
  
end  
   
function function2(e)  
 -- Right  
 transition.to( wave1, {time=10000, x=1620, onComplete=function1})  
 transition.to( wave2, {time=10000, x=1})  
end  
  
-- Right  
transition.to( wave1, {time=10000, x=1620, onComplete=function1})  
-- Left  
transition.to( wave2, {time=10000, x=1})  
  

Again, thanks all for the help!

[import]uid: 50459 topic_id: 14330 reply_id: 53111[/import]