电晕故事板调度事件错误

时间:2013-06-29 21:04:37

标签: corona corona-storyboard

我在电晕模拟器中遇到以下错误。我所知道的文件中没有任何变化。 (我已经包含了main.lua代码和menuMain.lua代码。)如果您对可能导致的内容有任何想法,那将会被批评! =)谢谢。


电晕模拟器运行时错误 档案:? 尝试调用方法'dispatchEvent'(零值) 堆栈追溯: [c]在函数'dispatchEvent'中 ?在功能gotoScene ... dwegrecki / main.lua:16 in main chunck


- main.lua

-- Hide Status Bar
display.setStatusBar(display.HiddenStatusBar)

-- require controller module
local storyboard = require "storyboard"

-- load first screen
storyboard.gotoScene( "menuMain" )

- menuMain.lua

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

---------------------------------------------------------------------------------
-- BEGINNING OF IMPLEMENTATION
---------------------------------------------------------------------------------
    local mainBg
    local titleIcon
    local startBtn
    local aboutBtn
    local onStartBtnTouch = {}
    local scene = {}


    -- Touch event listener for startBtn
local function onStartBtnTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "menuLevel", "fade", 400  )
            return true
        end
end

    -- Touch event listener for cerditsBtn
local function onCreditsBtnTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "zerocredits", "fade", 400  )
            return true 
        end
end

-- Called when the scene's view does not exist:
function scene:createScene( event )
    local screenGroup = self.view

    mainBg = display.newImage('bg.png')
    titleBg = display.newImage('title.png', 0, 100)
    playBtn = display.newImage('playBtn.png', 200, 240)
    creditsBtn = display.newImage('creditsBtn.png', 200, 290)
    titleView = display.newGroup(titleBg, playBtn, creditsBtn)

    screenGroup:insert( titleBg, playBtn, creditsBtn )

    playBtn.touch = onStartBtnTouch
    creditsBtn.touch = onCreditsBtnTouch

end

-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
    print( "1: enterScene event" )

    -- remove previous scene's view
    storyboard.purgeScene( "LevelMenu" )
    storyboard.purgeScene( "credits" )
    storyboard.purgeScene("main")

end

-- Called when scene is about to move offscreen:
function scene:exitScene( event )
    print( "1: exitScene event" )

    -- remove touch listener for image
    mainBg:removeEventListener( "touch", mainBg )
end

-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
    print( "((destroying scene 1's view))" )
end

---------------------------------------------------------------------------------
-- END OF IMPLEMENTATION
---------------------------------------------------------------------------------

scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )

---------------------------------------------------------------------------------

return scene

1 个答案:

答案 0 :(得分:1)

我重新创建了与你相同的项目,我在local scene = {}上收到错误为什么你把变量场景作为一个表?