- 这就是错误
Line: 131
--Attempt to call method 'addEventListeners' (a nil value)
--stack traceback:
-- menu.lua:131: in function 'startButtonListeners'
-- menu.lua:179: in function <menu.lua:32> --"startButtonListeners('add')"--
-- ?: in function 'dispatchEvent'
-- ?: in function 'gotoScene'
- 我无法理解我必须放在哪里&#34; startButtonListeners('add')
&#34;
local sceneGroup = self.view
background = display.newImageRect( "img/bg.png", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
titleLogo = display.newImageRect( "img/title.png", 356, 132 )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 150
-- button2
tasto2 = display.newImage('img/tasto2.png', 356,66)
tasto2.x = display.contentWidth *0.5
tasto2.y = 300
sceneGroup:insert( background )
sceneGroup:insert( titleLogo )
sceneGroup:insert( tasto2 )
--listener "tap"
function startButtonListeners(action)
if (action == 'add') then
tasto2:addEventListeners ('tap', showInfo) --THIS IS LINE 131
else
tasto2:removeEventListeners ('tap', showInfo)
end
end
function showInfo:tap(e)
tasto2.isVisible = false
titleLogo.isVisible = false
infoView = display.newImage('img/bg.jpg', display.contentWidth *0.5, display.contentHeight *0.5)
lastY = titleLogo.y
transition.to(infoView,
{time = 400,
y = (display.contentHeight * 0.5) ,
onComplete = function()
infoView:addEventListener('tap', hideInfo) end})
end
function hideInfo:tap(e)
transition.to(infoView,
{time = 300,
y = display.contentHeight + 25,
onComplete = function()
tasto2.isVisible = true
titleLogo.isVisible = true`enter code here`
infoView:removeEventListener('tap', hideInfo)
display.remove(infoView) infoView = nil end})
transition.to(titleLogo, {time = 300, y = lastY});
end
startButtonListeners('add')
答案 0 :(得分:3)
您是否尝试过addEventListener?我不认为addEventListeners是一个有效的函数......
答案 1 :(得分:0)
可能是Corona无法从路径加载图片并返回nil?