- The nomenclature is clearer.
- You can trade out objects as the ‘receiver’ i.e. You can have a proxy object as ‘self’ and the collided object as “event.target”. This allows for unified processing of collisions when you need it.
- self passed as an argument is slightly faster than “local target = event.target” creation on each call. (Not really a motivator, but still better.)
- You can dynamically re-assign the listener w/o needing to remove and add, simply change the function ‘.collision’ is pointing to and the new function is called. This can be done any time, even mid-touch. I use this for easy creation of editors where touch, drag, drop functionality, and/or context changes. It keeps the individual touch listeners simple and short.
- More…
The point is, function listeners are simple, but not really flexible.
However, we should each code the way we are comfortable.
-Ed
Oh, and because SSK uses these extensively. For example:
local function onCollision( self, event ) ... code here end ssk.display.newImageRect( group, centerX, centerY, "images/smiley.png", -- add to group, sel image, place { size = 20, fill = \_RED\_, rotation = 25 }, -- Visual attributes { radius = 10, bounce = 1, collision = onCollision } ) -- Physics attributes
