使用widget.newButton()函数时出现gotoScene错误。
2014-10-23 11:47:51
收藏:0
阅读:200
评论:2
我正在使用Corona SDK制作一个游戏应用程序,当我点击我的接口中的开始按钮并尝试加载我的第一个场景时,出现了一个错误。
这是我的代码:
main.lua
local storyboard = require "storyboard"
storyboard.gotoScene("menu")
menu.lua
local storyboard = require("storyboard")
local scene = storyboard.newScene()
local widget = require("widget")
local background = display.newImage("Legend of Kael.jpg", true)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
local roundedRect = display.newRoundedRect(10, 50, 300, 40, 8)
roundedRect.anchorX, roundedRect.anchorY = 0.0, 0.0
roundedRect:setFillColor(0 / 255, 0 / 255, 0 / 255, 170 / 255)
local function handleButtonEvent(event)
if ("ended" == event.phase) then
storyboard.gotoScene("scene1", "crossFade", 400)
end
end
local button = widget.newButton {
defaultFile = "buttonBlue.png",
overFile = "buttonBlueOver.png",
label = "Start Game",
emboss = true,
onEvent = handleButtonEvent,
}
button.x = 240;
button.y = 200
function scene:createScene(event)
local group = self.view
end
function scene:enterScene(event)
storyboard.purgeScene("main")
local group = self.view
end
function scene:exitScene(event)
local group = self.view
storyboard.removeScene("main")
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
return scene
scene1.lua
local physics = require "physics"
physics.start()
local storyboard = require("storyboard")
local scene = storyboard.newScene()
function scene:createScene(event)
local background = display.newImage("forest1.jpg", display.contentWidth, display.contentHeight)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
local ground = display.newImage("ground.png")
ground:setReferencePoint(display.BottomLeftReferencePoint)
ground.x, ground.y = 0, 420
local groundShape = {-420, -20, 420, -20, 420, 20, -420, 20}
physics.addBody(ground, "static", {friction = 1.0, density = 1.0, bounce = 0, shape = groundShape})
local char = display.newImage("char.png")
char.x = 70
char.y = 230
physics.addBody(char, {friction = 1.0, density = 1.0, bounce = 0.3, radius = 35})
char.isFixedRotation = true
local function onScreenTouch(event)
if event.phase == "began" then
char:applyForce(100, -500, char.x, char.y)
end
return true
end
end
Runtime:addEventListener("touch", onScreenTouch)
scene:addEventListener("createScene", scene)
return scene
我得到的错误如下:
assertion failed!
stack traceback:
[C]: in function 'error'
?: in function 'gotoScene'
menu.lua:17:in function '_onEvent'
?: in function '?'
?: in function <?:424>
?: in function <?:218>
我希望你能在这个问题中找到解决方案。谢谢。 :)
点赞
用户1870706
我怀疑这是因为您从未向故事板的视图组(即 local group = self.view)添加任何内容。通常,您的背景和按钮应该在故事板的 createScene() 函数中。一旦创建了这些对象,您就可以将它们插入到场景的视图中…
例如,group:insert(background)。因为您的场景视图为空,所以可能会引发该错误。
Rob
2014-10-26 04:40:50
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
你应该研究一下 Composer,因为“不仅Composer更易于使用,而且将来也能让我们构建更好、更有趣的东西”。
至于你的错误,这很可能是因为storyboard试图调用一个并不存在的函数。我的最佳建议是你阅读Composer的相关文档,并仔细地逐步跟着教程学习。由于不再支持storyboard,而Composer会更容易些。