我如何修复这个错误?(Corona SDK)
2015-1-19 20:52:5
收藏:0
阅读:92
评论:2
所以,我从这段代码中得到了这个错误,我想知道我该怎么做才能让它工作。错误消息说“ERROR:表格期望。如果这是函数调用,则您可能使用了“。”而不是“:””我仍在学习Lua,所以这对我来说非常困惑,如果您能提供答案,我会非常感激。
function scene:create( event )
--声明变量
local sceneGroup = self.view
local background = display.newImage( "game_background.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
--对象“篮子”的旋转函数
local function rotateBasket(event)
--旋转函数内声明的变量
local t = event.target
local phase = event.phase
local basket = display.newImageRect("basket.jpg" , 90, 60)
basket.x = display.contentCenterX
basket.y = display.contentCenterY
--旋转
if (phase == "began") then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x1 = event.x
t.y1 = event.y
elseif t.isFocus then
if (phase == "moved") then
t.x2 = event.x
t.y2 = event.y
angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
rotationAmt = angle1 - angle2
t.rotation = t.rotation - rotationAmt
t.x1 = t.x2
t.y1 = t.y2
elseif (phase == "ended") then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
--事件监听器
basket:addEventListener("touch", rotateBasket)
return true
end
--场景组插入
sceneGroup:insert( background )
sceneGroup:insert( basket )
end
点赞
用户2653067
在函数内部声明了局部变量 basket 并试图将其插入到函数外的 scenegroup 中,但由于是局部变量,不能从函数外部访问。
-- 旋转对象“篮子”的功能函数
local function rotateBasket(event)
-- 在旋转函数内声明变量
local t = event.target
local phase = event.phase
local basket = display.newImageRect("basket.jpg" , 90, 60)
basket.x = display.contentCenterX
basket.y = display.contentCenterY
-- 旋转
if (phase == "began") then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x1 = event.x
t.y1 = event.y
elseif t.isFocus then
if (phase == "moved") then
t.x2 = event.x
t.y2 = event.y
angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
rotationAmt = angle1 - angle2
t.rotation = t.rotation - rotationAmt
t.x1 = t.x2
t.y1 = t.y2
elseif (phase == "ended") then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
-- 将篮子插入到 scenegroup 中
sceneGroup:insert( basket )
-- 事件监听器
basket:addEventListener("touch", rotateBasket)
return true
end
-- 在 scenegroup 中插入 background
sceneGroup:insert( background )
2015-01-30 11:43:51
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的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中获取用户配置主目录的跨平台方法
我认为你声名 'basket' 对象的方式有点错。你是在 'rotateBasket' 函数内声名的
basket,这会使得此 'basket' 在函数外无法访问。我假设你是要声名一个背景和一个要旋转的 'basket' 图像。假设你的rotateBasket函数是正确的,你可以尝试以下代码:--Rotation Function for Object "Basket" local function rotateBasket(event) --Declared Variables inside rotation function local t = event.target local phase = event.phase --Rotation if (phase == "began") then display.getCurrentStage():setFocus( t ) t.isFocus = true t.x1 = event.x t.y1 = event.y elseif t.isFocus then if (phase == "moved") then t.x2 = event.x t.y2 = event.y angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x) angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x) rotationAmt = angle1 - angle2 t.rotation = t.rotation - rotationAmt t.x1 = t.x2 t.y1 = t.y2 elseif (phase == "ended") then display.getCurrentStage():setFocus( nil ) t.isFocus = false end end return true end function scene:create( event ) --Declared variables local sceneGroup = self.view --Create background local background = display.newImage( "game_background.jpg", display.contentWidth, display.contentHeight ) background.anchorX = 0 background.anchorY = 0 background.x, background.y = 0, 0 --Create basket local basket = display.newImageRect("basket.jpg" , 90, 60) basket.x = display.contentCenterX basket.y = display.contentCenterY --Add event listener to basket (may also be done in scene:show function) basket:addEventListener("touch", rotateBasket) --sceneGroup insertions sceneGroup:insert( background ) sceneGroup:insert( basket ) end