Removing from table

Maybe i want to sleep, but still i have a probably stupid question)
i'm trying to spawn a 5 "fires" and one of them is transitioning to x = 300
and i'm trying to remove it upon passing x=200, but it doesnt work, so please help me, what i done wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local fires = {}
 
for i=1,5 do
 
local fire = display.newRect(0,0,20,10)
fire.x = 10
fires[i] = fire
fire.y = math.random(10,300)
transition.to(fires[1],{time=3000, x = 300})
end
 
local function collect()
 
        for i=1, #fires do
                if fires[i].x > 200 then
                fires[i]:removeSelf()
        end
end
end
 
Runtime:addEventListener("enterFrame", collect)

Hey @ darkconsoles, I edited yours a bit. And, you probably want to shoot the fire at random time, remove the enterFrame event listener after all 5 fires are removed.

EDIT: actually, instead of doing the loop, you may look into making the object transparent when it hits x = 200, and then, on completion of the transition, remove self instead of using the collect function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local fires = {}
for i=1,5 do
 
local fire = display.newRect(0,0,20,10)
fires[i] = fire
fires[i].x = 10;
fires[i].y = math.random(10,300)
transition.to(fires[i],{time=3000, x = 300})
end
 
local function collect()
 
       -- you probably want to go backward (i.e., remove from the max number of fires until #fires reaches 0).
       -- I just don't remember the syntax off the top of my head
       
        for i=1, #fires do 
                if fires[i].x > 200 then
                fires[i]:removeSelf()
        end
end
end
 
Runtime:addEventListener("enterFrame", collect) 
views:1501 update:2011/10/22 9:46:13
corona forums © 2003-2011