Hi,
I am using composer and an invisible layer in each scene to detect touch and swipe to change the scene. It works fine unless sometimes I swipe very fast in between scenes and one of these make the app crash (on simulator and device), I get a black screen sometimes with no error returned and sometimes I get this error:
attempt to call method ‘addEventListener’ (a nil value):
referred to the line where I put the listener on the layer that detect the swipes:
local swipeLayer = display.newRect( centerX, centerY, display.contentWidth, display.contentHeight ) swipeLayer.alpha=0 swipeLayer.isHitTestable = true sceneGroup:insert( swipeLayer ) local function startDrag(event) local swipeLength = math.abs(event.x - event.xStart) local t = event.target local phase = event.phase if "began" == phase then native.setKeyboardFocus( nil ) elseif "moved" == phase then elseif "ended" == phase or "cancelled" == phase then if event.xStart \> event.x and swipeLength \> 50 then composer.gotoScene("counter",{ effect= "dismissSceneToLeft", time=200}) elseif event.xStart \< event.x and swipeLength \> 50 then end end end local function sensitizeLayer () swipeLayer:addEventListener("touch", startDrag) -- error returned here end timer.performWithDelay(400, sensitizeLayer)
I also delay the declaration of the event listener to make sure the layer doens’t receive touches during transition but this doesn’t seem to work.
Any idea why this is happening?
Thanks!!!