Corona SDK屏幕转换不能在一个按钮上工作

时间:2013-11-01 23:40:48

标签: android ios mobile storyboard corona

我有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>

我该怎么办?

2 个答案:

答案 0 :(得分:0)

错误消息表明错误是由操作引起的:

storyboard.gotoScene("credits", "fade", 1000)

所以:

  • 确保您的credits.lua所在的文件夹中存在您的班级main.lua
  • 确保班级中的所有方法和变量都正确:credits.lua
  • LUA对资源区分大小写

    即。myImage.pngmyimage.pngMyImage.png以及myImage.jpg不同。

所以,确保这些事情是正确的......

继续编码...........

答案 1 :(得分:0)

您可能不应该使用“credits”(和credits.lua)作为名称。尝试将其重命名为gamecredits。有一个核心模块(它已被弃用,但显然仍然会导致问题)名为credit。

如果在将其重命名为gamecredits后仍有问题,那么您可能在该模块中出错。