Delayed scene loading

First time playing with Composer scenes so I may well be doing something stupid here, but I’m basically trying to string together a series of splash screens by constructing a table of scenes and transitions, and passing that as a parameter to each scene, so that it can be used within the scene:show function to trigger moving on to the next in the queue.

So, my main.lua looks like this (stripped back a little):

local initialScenes = { { scene = "scene1", transition = "zoomInOutFade", speed = 400, showFor = 2000 -- milliseconts to display scene for }, { scene = "scene2", transition = "zoomInOutFade", speed = 400, showFor = 2000 -- milliseconts to display scene for }, { scene = "scene3", transition = "zoomInOutFade", speed = 400 } } local composer = require( "composer" ) composer.gotoScene(initialScenes[1].scene, { effect = initialScenes[1].transition, time = initialScenes[1].speed, params = { scenes = initialScenes } })

Then, each of the scenes includes an instance of:

local scenesSequence = {}

And the following at the end of scene:create:

if(event.params.scenes ~= nil) then scenesSequence = event.params.scenes table.remove(scenesSequence, 1) end

Finally, in scene:show I have the following:

if ( phase == "did" ) then if(scenesSequence[1] ~= nil) then timer.performWithDelay(scenesSequence[1].showFor, composer.gotoScene(scenesSequence[1].scene, { effect = scenesSequence[1].transition, time = scenesSequence[1].speed, params = { scenes = scenesSequence } })) end end 

The concept works, but the timer in scene:show is firing immediately once the entry transition completes instead of waiting the showFor time. I’ve tried replacing that with a hard-coded 4000 but it’s still just an immediate fire.

Any thoughts please?

Ah, fixed.

Turns out performWithDelay fires the function immediately unless you leave out the parenthesis, so I’ve changed it to this:

if(scenesSequence[1] ~= nil) then timer.performWithDelay(scenesSequence[1].showFor, nextScene) end

And moved the gotoScene code into a local function:

function nextScene() composer.gotoScene(scenesSequence[1].scene, { effect = scenesSequence[1].transition, time = scenesSequence[1].speed, params = { scenes = scenesSequence } }) end 

Works a treat now!

Ah, fixed.

Turns out performWithDelay fires the function immediately unless you leave out the parenthesis, so I’ve changed it to this:

if(scenesSequence[1] ~= nil) then timer.performWithDelay(scenesSequence[1].showFor, nextScene) end

And moved the gotoScene code into a local function:

function nextScene() composer.gotoScene(scenesSequence[1].scene, { effect = scenesSequence[1].transition, time = scenesSequence[1].speed, params = { scenes = scenesSequence } }) end 

Works a treat now!