Image and performWithDelay problem

Hello everyone, and congratulations for the forum. Excuse my take but i’m italian.

I’ve created image with function performWithDelay

“tmr = timer.performWithDelay(20,spawn0rb,total_orbs);” .

When the time reaches zero I would like to delete all the orbs created with the function on the exiteScene, but I do not know how to do. :frowning: Can help me? Thanks

I was actually wondering this. Is there a quick way to just remove all objects from memory when you change seen?

Yes, but not just from memory, the images created in the scene

I’ve created 20 ball with this funtion

-> tmr = timer.performWithDelay(20,myballs,total_orbs);

and on the exitScene I would like to remove the exit all balls

In your spawnOrb() function, you need to save a reference to the orb.  Most people do this by putting it into a table:

local orbs = {}

local function spawnOrb()

     orbs[#orbs+1] = display.newImage(…)

     orbs[#orbs].x = yourXlocation

     orbs[#orbs].y = yourYlocation

… etc.

end

Note the first time we use #orbs+1 to add a new orb at the end of the table.  When that’s done, #orbs references the last entry.  Now that you have a list of orbs you can remove them with something like this:

for i = #orbs, 1, -1 do

     orbs[i]:removeSelf()

     orbs[i] = nil

end

I was actually wondering this. Is there a quick way to just remove all objects from memory when you change seen?

Yes, but not just from memory, the images created in the scene

I’ve created 20 ball with this funtion

-> tmr = timer.performWithDelay(20,myballs,total_orbs);

and on the exitScene I would like to remove the exit all balls

In your spawnOrb() function, you need to save a reference to the orb.  Most people do this by putting it into a table:

local orbs = {}

local function spawnOrb()

     orbs[#orbs+1] = display.newImage(…)

     orbs[#orbs].x = yourXlocation

     orbs[#orbs].y = yourYlocation

… etc.

end

Note the first time we use #orbs+1 to add a new orb at the end of the table.  When that’s done, #orbs references the last entry.  Now that you have a list of orbs you can remove them with something like this:

for i = #orbs, 1, -1 do

     orbs[i]:removeSelf()

     orbs[i] = nil

end