ui.lua menu buttons stick after leaving menu screen and returning twice

I’ve got a basic menus screen with 9 buttons on it, all operated by the ui.lua package.

main.lua just calls a loader screen which pulls up the menu scene:

local storyboard = require(“storyboard”)
local scene = storyboard.newScene( )

local ui = require(“ui”)
local btnAnim
local btnSound = audio.loadSound( “btnSound.wav” )

local _w = display.contentWidth/2
local _h = display.contentHeight/2

local motorBtn
local cableBtn
local groundBtn
local referenceBtn
local arcflashBtn
local pfBtn
local calcsBtn
local journalBtn
local creditsBtn
function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene( “creditScreen” ) --Remove previous screens
– storyboard.removeScene( “” ) --Remove previous screens
print("\nmainmenu:createScene event")

end

function scene:enterScene(event)
local screenGroup = self.view
print(“mainmenu:enterScene event”)
local backgroundImage = display.newImageRect( “mainMenuBG.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage)

local motorBtn

local onMotorTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto motor file”)
end
end

motorBtn = ui.newButton{ defaultSrc = “motorBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “motorBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onMotorTouch,
id = “MotorButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
motorBtn.x =360; motorBtn.y = 390

screenGroup:insert(motorBtn)
local cableBtn

local onCableTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto cable file”)
end
end

cableBtn = ui.newButton{ defaultSrc = “cableBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “cableBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onCableTouch,
id = “CableButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
cableBtn.x =820; cableBtn.y = 390

screenGroup:insert(cableBtn)
local groundBtn

local onGroundTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto ground file”)
end
end

groundBtn = ui.newButton{ defaultSrc = “groundBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “groundBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onGroundTouch,
id = “GroundButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
groundBtn.x =1260; groundBtn.y = 390

screenGroup:insert(groundBtn)
local referenceBtn

local onReferenceTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto reference file”)
end
end

referenceBtn = ui.newButton{ defaultSrc = “referenceBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “referenceBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onReferenceTouch,
id = “ReferenceButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
referenceBtn.x =1720; referenceBtn.y = 390

screenGroup:insert(referenceBtn)
local arcflashBtn

local onArcflashTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto arcflash file”)
end
end

arcflashBtn = ui.newButton{ defaultSrc = “arcflashBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “arcflashBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onArcflashTouch,
id = “ArcflashButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
arcflashBtn.x =360; arcflashBtn.y = 990

screenGroup:insert(arcflashBtn)
local pfBtn

local onPfTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto power factor file”)
end
end

pfBtn = ui.newButton{ defaultSrc = “pfBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “pfBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onPfTouch,
id = “PfButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
pfBtn.x =820; pfBtn.y = 990

screenGroup:insert(pfBtn)
local calcsBtn

local onCalcsTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto calculations file”)
end
end

calcsBtn = ui.newButton{ defaultSrc = “calcsBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “calcsBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onCalcsTouch,
id = “CalcsButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
calcsBtn.x =1260; calcsBtn.y = 990

screenGroup:insert(calcsBtn)
local journalBtn

local onJournalTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
– storyboard.gotoScene( “loadgame” ,“fade”, 300 ) --Direct to motor file
print(“goto journal file”)
end
end

journalBtn = ui.newButton{ defaultSrc = “journalBtn.png”, defaultX = 360, defaultY = 360,
overSrc = “journalBtn-pressed.png”,
overX = 360,
overY = 360,
onEvent = onJournalTouch,
id = “JournalButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
journalBtn.x =1720; journalBtn.y = 990

screenGroup:insert(journalBtn)
local creditsBtn

local onCreditsTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “creditsScreen” ,“fade”, 300 ) --Direct to creditScreen file
print(“goto credits file”)
end
end

creditsBtn = ui.newButton{ defaultSrc = “creditsBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “creditsBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onCreditsTouch,
id = “CreditsButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
creditsBtn.x = display.contentCenterX; creditsBtn.y = 1420

screenGroup:insert(creditsBtn)

end
function scene:exitScene()
if btnAnim then
transition.cancel(btnAnim); end
print(“mainmenu:exitScene event”)

end

function scene:destroyScene(event)
print("((destroying mainmenu’s view))")
end

scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene )

return scene

I haven’t built any of the screens for the other menu buttons but have done the creditsScreen. Since this is the only one I have, it must be part of the problem but I need to find this before I do all the other screens. When I go to the credits screen, back to menu, to the credits screen, and then back to menu, the menu buttons all stick, as though the ‘release’ event is not occuring. I notice that when I first exit the menu, storyboard records the ‘destroyScene’ event but does not when I leave to go to the creditsScreen the second time through.

Here’s the creditsScreen:

local ui = require(“ui”)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene ( )
local menuBtn
local btnSound = audio.loadSound( “btnSound.wav” )

function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene ( “mainmenu” )
print("\ncreditsScreen:createScene event")
end

function scene:enterScene(event)
local screenGroup = self.view
print(“creditsScreen:enterScene event”)
backgroundImage = display.newImageRect ( “creditsScreen.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage)

local menuBtn

local onMenuTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “mainmenu” ,“fade”, 300 ) --Direct to mainmenu file
print(“goto mainmenu from credits file”)
end
end

menuBtn = ui.newButton{ defaultSrc = “menuBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “menuBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onMenuTouch,
id = “MenuButton”,
text = " ",
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
menuBtn.x = 1780; menuBtn.y = 1420

screenGroup:insert(menuBtn)

end

function scene:exitScene()
print(“creditsScreen:exitScene event”)

end

function scene:destroyScene(event)
print("((destroying creditsScreen’s view))")
end

scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene )
return scene

I am just learning so need some help troubleshooting this. The menubuttons still work and send out the command to terminal and the “click” sound file, but they remain in their ‘pressed’ position on screen.

Thanks,
George [import]uid: 214528 topic_id: 35761 reply_id: 335761[/import]

Hi George. That’s a lot of code to look at in particular when it’s unformatted. If you can edit your post and use <code> and </code> tags around the code it will help a lot.
[import]uid: 199310 topic_id: 35761 reply_id: 142280[/import]

I’ve got a basic menu screen with 9 buttons on it, all operated by the ui.lua package. (Rob, sorry about the mess on the first post…) main.lua just calls a loader screen which pulls up the menu scene - mainmenu.lua: local storyboard = require(“storyboard”)
local scene = storyboard.newScene( ) local ui = require(“ui”)
local btnAnim
local btnSound = audio.loadSound( “btnSound.wav” ) local _w = display.contentWidth/2
local _h = display.contentHeight/2 local motorBtn
local cableBtn
local groundBtn
local referenceBtn
local arcflashBtn
local pfBtn
local calcsBtn
local journalBtn
local creditsBtn
function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene( “creditScreen” ) --Remove previous screens
– storyboard.removeScene( “” ) --Remove previous screens
print("\nmainmenu:createScene event") end function scene:enterScene(event)
local screenGroup = self.view
print(“mainmenu:enterScene event”)
local backgroundImage = display.newImageRect( “mainMenuBG.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage) – 9 buttons but just the “creditsScreen” shown: local creditsBtn local onCreditsTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “creditsScreen” ,“fade”, 300 ) --Direct to creditScreen file
print(“goto credits file”)
end
end creditsBtn = ui.newButton{ defaultSrc = “creditsBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “creditsBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onCreditsTouch,
id = “CreditsButton”,
text = " “,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
creditsBtn.x = display.contentCenterX; creditsBtn.y = 1420 screenGroup:insert(creditsBtn) end
function scene:exitScene()
if btnAnim then
transition.cancel(btnAnim); end
print(“mainmenu:exitScene event”) end function scene:destroyScene(event)
print(”((destroying mainmenu’s view))")
end scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene ) return scene
–The creditsScreen.lua code below just displays a PNG file with a “Return to Menu” button on it: --display the credits
local ui = require(“ui”)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene ( )
local menuBtn
local btnSound = audio.loadSound( “btnSound.wav” ) function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene ( “mainmenu” )
print("\ncreditsScreen:createScene event")
end function scene:enterScene(event)
local screenGroup = self.view
print(“creditsScreen:enterScene event”)
backgroundImage = display.newImageRect ( “creditsScreen.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage) local menuBtn local onMenuTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “mainmenu” ,“fade”, 300 ) --Direct to mainmenu file
print(“goto mainmenu from credits file”)
end
end menuBtn = ui.newButton{ defaultSrc = “menuBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “menuBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onMenuTouch,
id = “MenuButton”,
text = " “,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
menuBtn.x = 1780; menuBtn.y = 1420 screenGroup:insert(menuBtn) end function scene:exitScene()
print(“creditsScreen:exitScene event”) end function scene:destroyScene(event)
print(”((destroying creditsScreen’s view))")
end scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene )
return scene
[/lua] It seems that there is something up with the handling of screens by Storyboard because when testing this, going to the creditsScreen and back to mainmenu twice causes the ui.lua button handler to freeze the button overlays. The ui.lua code is missing the “release” event. I appreciate any suggestions in my quest to learn the Corona SDK. Best Regards,
George [import]uid: 214528 topic_id: 35761 reply_id: 142298[/import]

Hi George. That’s a lot of code to look at in particular when it’s unformatted. If you can edit your post and use <code> and </code> tags around the code it will help a lot.
[import]uid: 199310 topic_id: 35761 reply_id: 142280[/import]

I’ve got a basic menu screen with 9 buttons on it, all operated by the ui.lua package. (Rob, sorry about the mess on the first post…) main.lua just calls a loader screen which pulls up the menu scene - mainmenu.lua: local storyboard = require(“storyboard”)
local scene = storyboard.newScene( ) local ui = require(“ui”)
local btnAnim
local btnSound = audio.loadSound( “btnSound.wav” ) local _w = display.contentWidth/2
local _h = display.contentHeight/2 local motorBtn
local cableBtn
local groundBtn
local referenceBtn
local arcflashBtn
local pfBtn
local calcsBtn
local journalBtn
local creditsBtn
function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene( “creditScreen” ) --Remove previous screens
– storyboard.removeScene( “” ) --Remove previous screens
print("\nmainmenu:createScene event") end function scene:enterScene(event)
local screenGroup = self.view
print(“mainmenu:enterScene event”)
local backgroundImage = display.newImageRect( “mainMenuBG.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage) – 9 buttons but just the “creditsScreen” shown: local creditsBtn local onCreditsTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “creditsScreen” ,“fade”, 300 ) --Direct to creditScreen file
print(“goto credits file”)
end
end creditsBtn = ui.newButton{ defaultSrc = “creditsBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “creditsBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onCreditsTouch,
id = “CreditsButton”,
text = " “,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
creditsBtn.x = display.contentCenterX; creditsBtn.y = 1420 screenGroup:insert(creditsBtn) end
function scene:exitScene()
if btnAnim then
transition.cancel(btnAnim); end
print(“mainmenu:exitScene event”) end function scene:destroyScene(event)
print(”((destroying mainmenu’s view))")
end scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene ) return scene
–The creditsScreen.lua code below just displays a PNG file with a “Return to Menu” button on it: --display the credits
local ui = require(“ui”)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene ( )
local menuBtn
local btnSound = audio.loadSound( “btnSound.wav” ) function scene:createScene(event)
local screenGroup = self.view
storyboard.removeScene ( “mainmenu” )
print("\ncreditsScreen:createScene event")
end function scene:enterScene(event)
local screenGroup = self.view
print(“creditsScreen:enterScene event”)
backgroundImage = display.newImageRect ( “creditsScreen.png”, 2048, 1536 )
backgroundImage:setReferencePoint(display.CenterReferencePoint )
backgroundImage.x = display.contentCenterX
backgroundImage.y = display.contentCenterY
screenGroup:insert(backgroundImage) local menuBtn local onMenuTouch = function(event)
if event.phase == “release” then
audio.play(btnSound)
storyboard.gotoScene( “mainmenu” ,“fade”, 300 ) --Direct to mainmenu file
print(“goto mainmenu from credits file”)
end
end menuBtn = ui.newButton{ defaultSrc = “menuBtn.png”, defaultX = 400, defaultY = 140,
overSrc = “menuBtn-pressed.png”,
overX = 400,
overY = 140,
onEvent = onMenuTouch,
id = “MenuButton”,
text = " “,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false}
menuBtn.x = 1780; menuBtn.y = 1420 screenGroup:insert(menuBtn) end function scene:exitScene()
print(“creditsScreen:exitScene event”) end function scene:destroyScene(event)
print(”((destroying creditsScreen’s view))")
end scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
scene:addEventListener ( “exitScene”, scene )
scene:addEventListener ( “destroyScene”, scene )
return scene
[/lua] It seems that there is something up with the handling of screens by Storyboard because when testing this, going to the creditsScreen and back to mainmenu twice causes the ui.lua button handler to freeze the button overlays. The ui.lua code is missing the “release” event. I appreciate any suggestions in my quest to learn the Corona SDK. Best Regards,
George [import]uid: 214528 topic_id: 35761 reply_id: 142298[/import]