We created our own “change_scene” function to change scenes because using the “fade” parameter on gotoScene doesn’t fade everything out the way we like. Our version fades a black screen from 0 to 1 alpha, does a gotoScene, then fades the black screen alpha from 1 to 0 again.
The problem is that sometimes the game hangs while displaying the black screen. We don’t know why but we suspect it’s because of file I/O happening in the background. Here’s our code:
--[[------------------------------------------ change scenes a better way IN: scene = name of lua file t = time in milliseconds options = {} with composer options in it --------------------------------------------]] current\_scene\_id = nil local scene\_change\_transition function change\_scene( scene, t, options ) if scene\_change\_transition then log( "Unable to change scene to " .. scene .. ". There is already an active scene transition!", err, 5 ) return end local w, h = display.contentWidth, display.contentHeight local black = display.newRect( \_XC, \_YC, w \* 2, h \* 2 ) black:setFillColor( 0,0,0 ) -- black.anchorX, black.anchorY = 0,0 black.alpha = 0 -- fade to black if debug\_no\_fade then -- change scenes instantly local o = options if not o then o = { } end o.effect = nil log( "change\_scene instant = "..scene ) -- log( "change\_scene: mid fade." ) -- print\_r( o ) composer.gotoScene( scene, o ) current\_scene\_id = scene return end log( "change\_scene: begin fade." ) scene\_change\_transition = transition.to( black, { alpha = 1.0, time = t / 2, onComplete = function() scene\_change\_transition = nil -- change scenes instantly local o = options if not o then o = { } end o.effect = nil log( "globals: change\_scene = "..scene ) -- log( "change\_scene: mid fade." ) -- print\_r( o ) composer.gotoScene( scene, o ) current\_scene\_id = scene -- and fade back in & delete the black transition.to( black, { alpha = 0, time = t / 2, onComplete = function() -- scene\_change\_transition = nil -- log( "change\_scene: end fade." ) display.remove( black ) end } ) end } ) end