1

我在电晕模拟器中收到以下错误。据我所知,我的文件没有任何变化。(我已经包含了 main.lua 代码和 menuMain.lua 代码。)如果您对可能导致此问题的原因有任何想法,将不胜感激!=) 谢谢。


电晕模拟器运行时错误文件:?尝试调用方法“dispatchEvent”(一个零值)堆栈回溯:函数“dispatchEvent”中的[c]?在功能 gotoScene ...dwegrecki/main.lua:16 在主块中


-- 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
4

1 回答 1

1

我重新创建了与您的项目相同的项目,但我收到一个错误,local scene = {}说明您为什么将变量场景设为表格?

于 2013-06-30T00:32:42.777 回答