I’ve add to CPSs example a little and tested, and it definitely works:
local pick1, pick2 local counter = 0 function whichTap(self, event) if event.phase == "ended" then counter = counter + 1 if counter == 1 then pick1 = event.target else pick2 = event.target counter = 0 local firstX = pick1.x local firstY = pick1.y local secondX = pick2.x local secondY = pick2.y transition.to(pick2, {time = 1500, x = firstX, y = firstY}) transition.to(pick1, {time = 1500, x = secondX, y = secondY}) end end return true end local x = display.newRect( 100, 160, 50, 50) x:setFillColor(1, 0, 0) local y = display.newRect( 220, 160, 50, 50) y:setFillColor(0, 0, 1) x.touch = whichTap y.touch = whichTap x:addEventListener("touch", x) y:addEventListener("touch", y)
I know I’ve gotten upvalue errors like this before despite having forward-declared, and endured much frustration over it, only for it to be something simple. Alas, I can’t recall any examples.