How do you code an onComplete command?

I have a function that spawns objects (sprites) off-screen stage left, and sends them zipping across the screen to off-screen stage right. Here, they collect like flies on a windshield and (I believe) cause the CPU to bog down, as the game gradually slows to molasses-like speeds. I'm thinking that if I perform some sort of onComplete command to make the objects disappear once they have finished transitioning, I could take the load off the CPU. I'm not sure how to word an onComplete command, however. I'm new to Corona, so maybe I've got the wrong idea, but here's my object spawning code in case anyone has any sugg's:

1
2
3
4
5
6
7
8
9
local function scooterFunction()
  timer.performWithDelay(math.random(20,35), scooterFunction)
  local scooter = scooterFactory:newSpriteGroup()
  scooter.x = -100
  scooter.y = math.random(120,924)
  transition.to(scooter,  {time = math.random(1300,1400), delay = 0, x = scooter.x + 968}) 
  end
 
scooterFunction()

you can try this

1
transition.to(scooter,  {time = math.random(1300,1400), delay = 0, x = scooter.x + 968,onComplete=function() scooter :removeSelf() end})

My savior comes through for me yet again! Worked like a charm:)
Thanks Renjith.

Steven

you are welcome Steven...

Happy Coding :)

views:1401 update:2011/9/27 8:54:05
corona forums © 2003-2011