I have a table of game objects that I would like to delete after a slight delay due to an animation. The objects are stored in a table. After the deletion is triggered (i.e. the animation starts) the table is emptied. If new objects are spawned (and added to the same table) before the animation finishes, then the old objects are not deleted on animation completion. But if I wait and let the animation finish, the objects are deleted okay.
Code below:
local num = #self.line_parts
for i=1,num do
go.animate(self.line_parts[i], "scale", go.PLAYBACK_ONCE_FORWARD, 0.01, go.EASING_INBACK, 0.25, 0, function(self, url, property)
go.delete(url)
end)
end
self.line_parts = {}
Why doesn’t this work? Seems to be some sort of issue with referencing because adding more objects to the table appears to be the issue. But the table is emptied (reset even) regardless and it works so long as new objects aren’t added.
I know that animations of the same property interrupt the previous animation, which would cancel the callback. Indeed, the new objects have a scale animation applied on init. If I remove the scale animation then the callback fires and the old objects are deleted as intended.
What’s going on here?