我有 3 个按钮,故事板只会转换其中的 2 个。这是我的代码:
local storyboard = require "storyboard"
local scene = storyboard.newScene()
--Forward References
local mbg
local title
local pbtn
local ibtn
local cbtn
local centerX = display.contentCenterX
local centerY = display.contentCenterY
display.setStatusBar(display.HiddenStatusBar)
function anim_pbtn(event)
transition.to(pbtn, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("game", "fade", 1000)
end
function anim_ibtn(event)
transition.to(ibtn, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("leaderboard", "fade", 1000)
end
function anim_cbtn(event)
transition.to(cbtn, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("credits", "fade", 1000)
end
function scene:createScene(event)
local screenGroup = self.view
mbg = display.newImage("mbg.png")
screenGroup:insert(mbg)
mbg.x = centerX
mbg.y = centerY
mbg.width = display.width
mbg.height = display.height
title = display.newImage("title.png")
screenGroup:insert(title)
title.xScale = .7
title.yScale = .7
title.x = centerX
pbtn = display.newImage("play_btn.png")
screenGroup:insert(pbtn)
pbtn.xScale = .7
pbtn.yScale = .7
pbtn.x = centerX
pbtn.y = display.contentHeight - 210
ibtn = display.newImage("ins_btn.png")
screenGroup:insert(ibtn)
ibtn.xScale = .7
ibtn.yScale = .7
ibtn.x = centerX
ibtn.y = display.contentHeight - 130
cbtn = display.newImage("cre_btn.png")
screenGroup:insert(cbtn)
cbtn.xScale = .7
cbtn.yScale = .7
cbtn.x = centerX
cbtn.y = display.contentHeight - 50
end
function scene:enterScene(event)
pbtn:addEventListener("tap", anim_pbtn)
ibtn:addEventListener("tap", anim_ibtn)
cbtn:addEventListener("tap", anim_cbtn)
end
function scene:exitScene(event)
pbtn:removeEventListener("tap", anim_pbtn)
ibtn:removeEventListener("tap", anim_ibtn)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene
cbtn 按钮和 anim_cbtn 功能是什么问题导致屏幕没有过渡?我确实有一个 game.lua、leaderboard.lua 和一个 credits.lua 文件。我在 java 方面很棒,但在 lua 方面我很糟糕。我永远找不到我的错误。这是我的错误:
Runtime error
?:0: attempt to call method 'dispatchEvent' (a nil value)
stack traceback:
[C]: in function 'dispatchEvent'
?: in function 'gotoScene'
...ibrary/Application Support/Outlaw/Sandbox/6/menu.lua:27: in function <...ibrary/Application Support/Outlaw/Sandbox/6/menu.lua:25>
?: in function <?:218>
我应该怎么办?