故事板中的dispatchEvent错误

时间:2014-03-18 08:58:48

标签: lua corona

当我按下菜单中的信用按钮时,它给了我一个错误"?:0:尝试调用方法' dispatchEvent' (零值)?:在函数' gotoScene' ... scene_menu.lua:35:在函数中... scene_menu.lua:33>?:在函数" ...什么是问题在这里?

这是我的菜单页

-- scene_menu.lua

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

-- Clear previous scene
storyboard.removeAll()

--forward references
local background
local title
local playGame
local tutorial 
local credits


display.setStatusBar(display.HiddenStatusBar)



function playgameBtn( event )
  transition.to(playGame, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
  storyboard.gotoScene("playgame", "fade", 1000)
end

function tutorialBtn (event)
  transition.to(tutorial, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
  storyboard.gotoScene("tutorial", "fade", 1000)
 end

 function creditsBtn (event)
  transition.to(credits, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
  storyboard.gotoScene("credits", "fade", 1000)
 end

 function scene:createScene(event)
 local group = self.view

 background = display.newImage( "bkg_clouds.png")
 group:insert(background)
 background.x = 240
 background.y = 195


 title = display.newText("Shoot the Balloons!", 250, 100, native.systemFont, 25 )
 title:setFillColor( 1,1, 0 )


 playgame = display.newImage("Play Button.png")
 group:insert(playgame)
 playgame.x = 250
 playgame.y = 150

 tutorial = display.newImage("Tutorial Button.png")
 group:insert(tutorial)
 tutorial.x = 250
 tutorial.y = 200

 credits = display.newImage("Credits Button.png")
 group:insert(credits)
 credits.x = 250
 credits.y = 250
 end

function scene:enterScene( event )
    playgame:addEventListener("tap", playgameBtn)
    tutorial:addEventListener("tap", tutorialBtn)
    credits:addEventListener("tap", creditsBtn)
  end

function scene:exitScene(event)
playgame:removeEventListener("tap", playgameBtn)
tutorial:removeEventListener("tap", tutorialBtn)
credits:removeEventListener("tap", creditsBtn)
end

function scene:destroyScene(event)

end

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

return scene

这是我的main.lua

-- main.lua
display.setStatusBar( display.HiddenStatusBar )                 
local storyboard = require "storyboard"                               
storyboard.gotoScene( "scene_splash" )  

1 个答案:

答案 0 :(得分:0)

将credit.lua名称更改为其他名称或更改变量名称信用全局变量,我认为这是由于此行中名称冲突:storyboard.gotoScene("credits", "fade", 1000)