removeSelf with delay - how to implement?

hey folks,
I’m a beginner and now having some issues.
Basicly I have a hero (in the middle of the screen) and falling objects from sky.

I want those objects to appear with a Delay of 2 seconds (that works like a charm in my code), but I also want to disapear them, when they go offscreen OR automaticly after 8 seconds. how can I implement that function in my code?

--RAIN  
drops = 0 --Counter  
  
RemoveDrop = function()  
 i:removeSelf()  
 i = nil  
  
 drops = drops-1 --Counter  
  
 MakeItRain() --Loop  
end  
  
AddDrop = function()  
 drops = drops+1 --Counter  
  
 local autoSize = math.random( 60, 120 )  
 i = display.newImageRect( "images/windows.png", autoSize, autoSize )  
 i.x = math.random( 0, device\_w )  
  
 physics.addBody( i, { density = 1.8, friction = 0.5, bounce = 0.2 } )  
 i.bodyType = "dynamic"  
  
 MakeItRain() --Loop  
end  
  
MakeItRain = function()  
 if( drops \< 4 ) then --Counter  
 timer.performWithDelay( 2000, AddDrop )  
 end  
 --timer.performWithDelay( 8000, RemoveDrop )  
end  
MakeItRain()  

First I thought that I would be able to do this If every Image would have a different name. So I can talk to each Image independently… What do you think? I’m just going crazy… stuggling about 2 days now :frowning: [import]uid: 73502 topic_id: 12565 reply_id: 312565[/import]

I would do this with an enterFrame listener and a table that holds your raindrops.

take a look at my simple particle explosion:
http://developer.anscamobile.com/code/simple-particle-explosion#comment-42115

each time a raindrop spawns it is added to a table named particles. in that way you can simply adress each particle by iterating through that table and move or remove it.

as for the delay… hmm. let me think [import]uid: 70635 topic_id: 12565 reply_id: 45955[/import]