Understand event's propagation depth in display hierachy

–[[

Is there a way to understand how many display objects have been hit before,
i.e understand the event’s propagation deepth ?

  • i don’t want to use a global counter

  • unfortunately, event seems to be passed by value, and therefore my modifications to the event don’t stick

Click on the rectangle to run it

]]–

local r2 = display.newRect( 10,10,50,50)
local r1 = display.newRect( 10,10,50,50)

r1:addEventListener(“tap”, function(e) e.depth= ( e.depth and e.depth +1 ) or 1 print(e.depth) return false end)
r2:addEventListener(“tap”, function(e) e.depth= ( e.depth and e.depth +1 ) or 1 print(e.depth) return false end)

– getting
1
1

  • want
    1
    2

any ideas

Each event is generating a new event table.  There really isn’t a way using that table to accumulate data from event to event.  You don’t have to use a global, but you could use a local “upvalue” to track it

Each event is generating a new event table.  There really isn’t a way using that table to accumulate data from event to event.  You don’t have to use a global, but you could use a local “upvalue” to track it