Hi my case is a little special, so i have not found a satisfactory solution for it on the forums (or didn’t understood it).
I am making a general function for restarting a game for newbies without using storyBoard (its too complex for new users to want to use it, i have to introduce the plataform slowly for then)
my restart function looks like this:
function restart(imagemBotao,posX,posY,vetorImagens,vetorTimers)
botaodeRestart = display.newImage(imagemBotao,posX,posY)
function restartarOApp()
if #vetorImagens > 0 then
for i=1, #vetorImagens do
vetorImagens[i]:removeSelf()
vetorImagens[i] = nil
end
end
if #vetorTimers > 0 then
for i=1,#vetorTimers do
timer.cancel(vetorTimers[i])
vetorTimers[i] = nil
end
end
botaodeRestart:removeSelf()
timer.performWithDelay(10,function() start() end,1)
end
botaodeRestart:addEventListener(“tap”,restartarOApp)
end
As you can see it removes the images and the timers with no problems.
i call this function on my main.lua using the line:
vida.restart(“botao.png”,600,100,{basketFundo,basketFrente,tabela,barreira1,barreira2,barreira3,sensordospontos,grupoBolasECesta},{timerDasBolas})
It works like a charm.
the problem is that my program is running an eventListener for scoring and it acummulates.
Since the restart function works on a separated file “vida.lua”, it has to be removed anonymously.
is there a way to remove the eventListener on a non specific way?
I removed the object it is on but it keeps stacking every time i click the restart function.
i dont know how tomake my restart function remove all the listener as well.
Is there a way to hold the listener on the properties of the object so i can remove it anonymously?
something like:
if vetorImagens[i].listener == true then
vetorImagens[i]:removeEventListenervetorImagens[i].eType,vetorImagens[i].listener)
end
if there is an easy solution i ill be really pleased to know.
thanks
my best Regards