Removing Spawns Created in a Table

I’m having trouble removing the objects I have created using a loop.  Thanks


function spawn(params)

object = display.newImage(params.image)

object.objTable = params.objTable

object.index = #object.objTable + 1

object.enemy = "Object : " … object.index

object.group = params.group or nil

object.group:insert(object)

object.objTable[object.index] = object

object.x = 100

object.y = 100*object.index

transition.to(object.objTable[1], { x=400,time=500,onComplete=kill})

transition.to(object.objTable[2], { x=400,time=1000,onComplete=kill})

return object

end

function kill()

display.remove(object.objTable[object.index])

end


localGroup = display.newGroup()

spawnTable = {}

for i = 1,2 do

spawns = spawn({image = “image1.png”,

objTable = spawnTable,

group = localGroup,

})

end


Just for anyone who was having trouble with this…

function kill(obj)

    display.remove(obj)

end    

The onComplete=kill in the transition.to will kill the object that has just completed its transition.

Just for anyone who was having trouble with this…

function kill(obj)

    display.remove(obj)

end    

The onComplete=kill in the transition.to will kill the object that has just completed its transition.