2012-02-22 93 views
1

我是Corona SDK的初学者。 我有2个场景A & B.使用故事板似乎禁用触摸事件?

在场景中我有一个OnRelease事件按钮。 此按钮已创建并添加到场景创建事件中的组中。 点击按钮将我带到场景B(storyboard.gotoScene(“B”))。

在场景B我有一个盒子上的触摸事件(箱子图像)。 触摸侦听器添加到场景中的已启动事件中,并在现场退出事件中删除。 点击箱子把我带回A(storyboard.gotoScene(“A”))。

所以这里是真正令人讨厌的问题: 回到A后,此场景中的所有事件现在都被禁用。 即我不能再点击按钮(无事件)。

如果我缺少上述信息,将提供代码片段。 谢谢。

*更新*

取约从这个休息后,我今天回去又开始调试这一点。我很快就发现了这个问题。这个问题与我触摸的事件处理程序有关(导致从场景B到A的过渡)。

低于片断导致此问题:

function testTouched(event) 

-- process cue-touched event... 
--local t = event.target -- commenting this was the fix. 
local phase = event.phase 

if "began" == phase then 

     print("  -> back to menu") 
     --display.getCurrentStage():setFocus(t) -- commenting this was the fix. 
     --t.isFocus = true -- commenting this was the fix. 
     storyboard.gotoScene("menu", "flipFadeOutIn", 500) 

end 

-- Stop further propagation of touch event 
return true 
+0

是的,你应该提供代码片段 – cctan 2012-02-23 08:30:30

回答

0

从我看到here

enterScene

时storyboard.gotoScene()被调用调度, 过渡后立即已完成。因此,如果您指定了过渡效果, 只要效果结束,就会分派此事件。添加 听众,或应用程序/游戏特定的逻辑应放置在此事件的听众 函数中。

exitScene

当storyboard.gotoScene()被调用时,一个“exitScene”事件将是 的过渡发生之前分派到当前显示的场景。 清理任务,如删除事件侦听器,停止定时器, 等应放置在此事件的侦听器函数中。

添加事件侦听器enterScene()事件,而不是createScene()exitScene()删除它们?

编辑:我想你需要display.getCurrentStage():setFocus(nil)exitScene()