I got this simple problem that I can’t seem to fix. My app using the Storyboard API. I have simple buttons that uses the Storyboard API that takes the user back and forth between screens aka Lua files. When a new lua files is loaded it works great. But if the user leave that screen and then returns then all of the elements get merged (PNG Files, objects, etc.) from both screens (lua files). Just wanted to know what the best way to fix this is. [import]uid: 6134 topic_id: 28820 reply_id: 328820[/import]
Post some code please. I can’t imagine what’s going on, from the top of my head… maybe you’re not adding your objects to the scene’s view group? [import]uid: 144908 topic_id: 28820 reply_id: 116161[/import]
That’s 99% likely the cause. Any display objects that get created in a scene need to be put into the “group” display group or storyboard won’t remove them when the scene goes away.
[import]uid: 19626 topic_id: 28820 reply_id: 116175[/import]
Attached is my menu.lua file:
-----------------------------------------------------------------------------------------
--
-- Rock the Blockz (Sideways) 1.2 menu.lua
--
-----------------------------------------------------------------------------------------
-- hide the status bar
-- display.setStatusBar( display.HiddenStatusBar )
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "widget" library
local widget = require "widget"
--------------------------------------------
-- forward declarations and other locals
local playBtn
local contactBtn
-- 'onRelease' event listener for playBtn
local function onPlayBtnRelease()
-- go to level1.lua scene
storyboard.gotoScene( "level1", "fade", 500 )
return true -- indicates successful touch
end
-- 'onRelease' event listener for contactBtn
local function oncontactBtnRelease()
-- go to level1.lua scene
storyboard.gotoScene( "contact", "fade", 500 )
return true -- indicates successful touch
end
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- display a background image
local background = display.newImageRect( "bkg\_clouds.png", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
-- create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( "logo2.png", 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth \* 0.5
titleLogo.y = 20
-- create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label="Play Now",
labelColor = { default={255}, over={128} },
default="button.png",
over="button-over.png",
width=154, height=40,
onRelease = onPlayBtnRelease -- event listener function
}
-- create a widget button (which will loads contact.lua on release)
contactBtn = widget.newButton{
label="contact",
labelColor = { default={255}, over={128} },
default="button.png",
over="button-over.png",
width=154, height=40,
onRelease = oncontactBtnRelease -- event listener function
}
-- playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = 250
playBtn.y =110
-- contactBtn:setReferencePoint( display.CenterReferencePoint )
contactBtn.x = 250
contactBtn.y = 150
-- playBtn:setReferencePoint( display.CenterReferencePoint )
-- playBtn.x = display.contentWidth\*0.5
-- playBtn.y = display.contentHeight - 125
-- contactBtn:setReferencePoint( display.CenterReferencePoint )
-- contactBtn.x = display.contentWidth\*0.5
-- contactBtn.y = display.contentHeight - 75
-- all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
group:insert( contactBtn )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
if playBtn then
playBtn:removeSelf() -- widgets must be manually removed
playBtn = nil
end
if contactBtn then
contactBtn:removeSelf() -- widgets must be manually removed
contactBtn = nil
end
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
And here is my contact.lua file:
-----------------------------------------------------------------------------------------
--
-- Rock the Blockz (Sideways)1.2 Contact.lua
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "widget" library
local widget = require "widget"
--------------------------------------------
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- display a background image
local background = display.newImageRect( "bkg\_clouds.png", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
-- create/position logo/title image on upper-half of the screen
--local titleLogo = display.newImageRect( "logo2.png", 264, 42 )
-- titleLogo:setReferencePoint( display.CenterReferencePoint )
-- titleLogo.x = display.contentWidth \* 0.5
-- titleLogo.y = 100
local myText = display.newText( "Rock the Blockz !", 0, 0, native.systemFont, 40 )
myText.x = 250
myText.y = 25
--myText.x = display.contentWidth / 2
--myText.y = display.contentWidth / 4
--myText:setTextColor( 255,110,110 )
local myText = display.newText( "Created by: Timbojill, Inc. !", 0, 0, native.systemFont, 40 )
myText.x = 250
myText.y = 75
--myText.x = display.contentWidth / 2
--myText.y = display.contentWidth / 4
--myText:setTextColor( 255,110,110 )
local myText = display.newText( "E-mail:Timbojill@gmail.com", 0, 0, native.systemFont, 38 )
myText.x = 250
myText.y = 115
--myText.x = display.contentWidth / 2
--myText.y = display.contentWidth / 4
--myText:setTextColor( 255,110,110 )
-- CODE BELOW FOR BACK BUTTON
-- forward declarations and other locals
local backBtn
-- 'onRelease' event listener for playBtn
local function onbackBtnRelease()
-- go to menu.lua scene
storyboard.gotoScene( "menu", "fade", 500 )
return true -- indicates successful touch
end
-- create a widget button (which will loads menu.lua on release)
backBtn = widget.newButton{
label="Back",
labelColor = { default={255}, over={128} },
default="button.png",
over="button-over.png",
width=154, height=40,
onRelease = onbackBtnRelease -- event listener function
}
backBtn.x = 250
backBtn.y = 200
-- all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( backBtn )
-- Called immediately after scene has moved onscreen:
--function scene:enterScene( event )
-- local group = self.view
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
--function scene:destroyScene( event )
-- local group = self.view
if backBtn then
backBtn:removeSelf() -- widgets must be manually removed
backBtn = nil
end
-- CODE ABOVE FOR BACK BUTTON
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
Now I am able to go from the menu.lua file to the contact.lua files no problem. I have a back button that takes the user back to the menu.lua file from the contact.lua files but when I press the back button both files become merged. Labels, objects, jpegs etc gets merged from both files. Can someone tell me what i doing wrong ? [import]uid: 6134 topic_id: 28820 reply_id: 116413[/import]