我已经实现了一个函数,我添加了一个带有一些按钮的视图以及添加了Eventlistener。
使用按钮侦听器我转换到另一个视图并删除了最后一个视图但仍然按钮侦听器处于活动状态。
function loadingMenu()
playBtn = display.newImage('play-btn.png', 170, 130)
playBtn:addEventListener( "tap", listener )
instructionBtn = display.newImage('instructions-btn.png', 150, 164)
-- instructionBtn:addEventListener( "tap", instructionListener )
creditBtn = display.newImage('credits-btn.png', 180, 201)
--creditBtn:addEventListener( "tap",ceditsListener )
titleBg = display.newImage('background-with-title.png')
--titleView = display:newGroup()
titleView = display.newGroup(titleBg, playBtn, instructionBtn,creditBtn)
end
function listener(event)
if titleView ~= nil then
playBtn:removeEventListener( "tap", listener )
transition.to(titleView, {time = 300, y = -titleView.width, onComplete = function() --startButtonListeners('rmv') --titleView:removeSelf() display.remove(titleView) titleView = nil end})
end
return true
end
提前致谢
答案 0 :(得分:1)
试试这个。这将有效...
----------------------------------------------------------------------------
local playBtn,instructionBtn,creditBtn,titleBg,titleView
----------------------------------------------------------------------------
function newfunction()
print("inside newfunction...")
end
----------------------------------------------------------------------------
function listener()
print("inside listener...")
if titleView ~= nil then
playBtn:removeEventListener( "tap", listener )
transition.to(titleView, {time = 300, y = -titleView.width, onComplete = newfunction()}) --startButtonListeners('rmv') --titleView:removeSelf() display.remove(titleView) titleView = nil end})
end
return true
end
----------------------------------------------------------------------------
function loadingMenu()
playBtn = display.newImage("play-btn.png", 170, 130)
instructionBtn = display.newImage("instructions-btn.png", 150, 164)
creditBtn = display.newImage("credits-btn.png", 180, 201)
titleBg = display.newImage("background-with-title.png")
titleView = display.newGroup(titleBg, playBtn, instructionBtn,creditBtn)
playBtn:addEventListener( "tap", listener )
end
----------------------------------------------------------------------------
loadingMenu()
----------------------------------------------------------------------------