Hi, I want destroy spawned objects (that spawn every 1 sec randomly in the screen) touching them.
I looked around the web for a solution but nobody has asked a thing like this.
This is my code: (thunder is my object that spawns every 1 sec and I want to destroy when I touch him)
With this code the first object that spawns I can destroy him but the others no.
local thunder = display.newImageRect( "thunder\_icon.png",100,100) thunder.x = larghezza / 2 thunder.y = altezza / 2 local spawnTimer local function myToccoListener(event) display.remove(thunder) return true end thunder:addEventListener("touch", myToccoListener) local spawn = function() local xCoord = math.random(display.contentWidth \* 0, display.contentWidth \* 1.0) local thunder = display.newImageRect( "thunder\_icon.png",100,100) thunder.x = xCoord thunder.y = 50 end spawnTimer = timer.performWithDelay(1000, spawn, -1)