difference between dispatchEvent and calling Listener directly?

-- Create an object that listens to events local image = display.newImage( "image.png" ) -- Setup listener local myListener = function( event ) print( "Event " .. event.name ) print( "Target has width: " .. event.target.contentWidth ) end image:addEventListener( "myEventType", myListener ) -- Sometime later, create an event and dispatch it local event = { name="myEventType", target=image } image:dispatchEvent( event ) ------------------- -- OR just call directly. ------------------- myListener(event)

Considering this code.  What is the difference between using dispatchEvent and just calling the listener directly?   

Is there a time delay when using dispatchEvent?   

Can you use dispatchEvent in a collision listener to get around the “No physics changes in collision listener” rule?   

none, unless it were a Runtime dispatch (as you might not necessarily know “who all” was listening)

no, apart from some trivial overhead (of going “through” the object to “lookup” the listener fn)

no, but you can use timer.performWithDelay (or create your own “to do list” for post-physics processing)

Generally I only use dispatchEvent from the Runtime object, where I have multiple objects that may be listening for one event.

It’s much easier to call:

Runtime:dispatchEvent({name = "myEventType"})

and let all of the listeners for that event name catch it, rather than calling the listener for each object manually (or dispatching events for every single object separately).

none, unless it were a Runtime dispatch (as you might not necessarily know “who all” was listening)

no, apart from some trivial overhead (of going “through” the object to “lookup” the listener fn)

no, but you can use timer.performWithDelay (or create your own “to do list” for post-physics processing)

Generally I only use dispatchEvent from the Runtime object, where I have multiple objects that may be listening for one event.

It’s much easier to call:

Runtime:dispatchEvent({name = "myEventType"})

and let all of the listeners for that event name catch it, rather than calling the listener for each object manually (or dispatching events for every single object separately).