My third day with Corona and I’ve pretty much got the beginnings of a game up and running but I’m still a bit woolly-headed with some of the event stuff.
I’ve got this cascading thing which handles a level-complete screen.
It appears.
Waits for a touch.
It Disappears.
Here’s the code:
local function levelCompleteExit()
levelCompleteScreen.isVisible = false
print("flag4")
if(levelNum \< numLevels) then
deleteLevel()
initLevel()
else
gameOver()
end
return true
end
local function levelCompleteTouched ( event )
print(event.phase)
print("flag2")
if event.phase == "ended" then
print("flag3")
local fadeLevelComplete = transition.to( levelCompleteScreen, { alpha=0.0, xScale=2.0, yScale=2.0, time=500, onComplete=levelCompleteExit } )
levelCompleteScreen.removeEventListener("touch", levelCompleteTouched)
end
return true
end
function levelComplete()
print("flag1")
levelCompleteScreen.alpha = 0
levelCompleteScreen.isVisible = true
levelCompleteScreen:toFront()
levelCompleteScreen.xScale = 2.0; levelCompleteScreen.yScale = 2.0
local showLevelComplete = transition.to( levelCompleteScreen, { alpha=1.0, xScale=1.0, yScale=1.0, time=500 } )
levelCompleteScreen:addEventListener( "touch", levelCompleteTouched )
end
levelCompleteTouched appears to be called more than once with the ‘ended’ phase and I really don’t want it to be.
I figured that the removal of the event listener from within the listener itself might be a bit shaky but with or without it, it seems to make no difference.
Any suggestions as to why my touch event is getting triggered twice?
[import]uid: 25233 topic_id: 5568 reply_id: 305568[/import]
[import]uid: 139976 topic_id: 5568 reply_id: 110411[/import]