Stop applicable emitter by touch and not by timer

Hi guys,

I am looking for a smart solution to stop  created  emitter by  touching it.

I am not interested for prescheduled timer.performWithDelay stop(s).

Also, I am not looking for **emitter:stop() **built in library, because I do not know where exactly is emitter onscreen…

So emitter is created by screen touch on event.x event.y position, and it is running/emitting.

function stopTouchedEmitter(self, event) if(event.phase == "began") then display.remove(self) self = nil end end function spawnEmitters(event) emitter = loader.newEmitter( "emitters/explosion.rg", "emitters/particle.png") emitter.x = event.x emitter.y = event.y emitter.touch = stopTouchedEmitter emitter:addEventListener( "touch", emitter )  emitterGroup:insert(emitter) emitterGroup:toFront() end

How to stop applicable touched emitter?

Above code does not work (I could iterate through emitterGroup and compare touch event.x and event.y with emitterGroup child(s) x and y… but that is too much workload :P ).

Many, many thanks!!

Ivan  :smiley:

Hi Ivan,

If I was doing this, I would create an invisible but hit-testable vector rectangle (or circle or whatever) for each emitter and associate the emitter with it as a child of that vector object. Then detect touches on those vector objects and take the proper action with its associated emitter.

Hope this helps,

Brent

Great suggestion, as always  :slight_smile:

Thanks Brent!

Hi Ivan,

If I was doing this, I would create an invisible but hit-testable vector rectangle (or circle or whatever) for each emitter and associate the emitter with it as a child of that vector object. Then detect touches on those vector objects and take the proper action with its associated emitter.

Hope this helps,

Brent

Great suggestion, as always  :slight_smile:

Thanks Brent!