I’m creating 2 groups when a scene is loaded. I only want one to show on screen, and then based on certain actions the second group may be shown later on.
The two groups are loading
and form
. So I show ‘loading’ (a little animation) while I check for something remote, and then show ‘form’ if I can’t find the remote resource.
To do this I would have assumed that I just add ‘loading’ to my group
. However, it seems they both show on screen regardless.
I can get the desired effect by setting form.isVisible = false;
but this seems a little bit wrong to me. I don’t want to set it as invisible as such, I just don’t want it to load in the first place. Is what I’m doing right here, or should I be seeking an alternative?
Full code here. Thanks:
[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require( “widget” )
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– create a white background to fill screen
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg:setFillColor( 80, 130, 200 ) – white
– Welcome
local title = txt.newEmbossed(“Welcome”, 10, 60, “Helvetica”, 32)
title:setTextColor( 255 ) – white
title:setReferencePoint( display.CenterReferencePoint )
title.x = display.contentWidth * 0.5
title.y = 75
– Welcome
local login = txt.newEmbossed(“Please login to begin.”, 10, 60, “HelveticaNeue”, 22)
login:setTextColor( 255 ) – white
login:setReferencePoint( display.CenterReferencePoint )
login.x = display.contentWidth * 0.5
login.y = 120
–[[FORM]]–
– Create new group for form
local form = display.newGroup();
– Labels and fields
local lblEmail = txt.new(“Email”, 40, 230, native.systemFont, 18)
local txtEmail = native.newTextField( 40, 255, 240, 36 )
txtEmail.font = native.newFont( native.systemFont, 22 )
local lblPassword = txt.new(“Password”, 40, 300, native.systemFont, 18)
local txtPassword = native.newTextField( 40, 325, 240, 36 )
txtPassword.font = native.newFont( native.systemFont, 22 )
local submit = widget.newButton{ label=“Login” }
submit.x = display.contentWidth * 0.5; submit.y = 400
– button
form:insert( lblEmail )
form:insert( txtEmail )
form:insert( lblPassword )
form:insert( txtPassword )
form:insert( submit )
–[[EO FORM]]–
–[[LOADING ANIMATION]]–
local loading = display.newGroup();
– Actual loading animation
local imgLoading = display.newImage( “images/loading.png” )
imgLoading.x = display.contentWidth * 0.5; imgLoading.y = 300
loading:insert(imgLoading)
–[[EO LOADING ANIMATION]]–
– all objects must be added to group (e.g. self.view)
group:insert( bg )
group:insert( title )
group:insert( login )
group:insert( loading )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– Do nothing
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
– INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)
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[/lua] [import]uid: 61422 topic_id: 25464 reply_id: 325464[/import]