First transition between storyboards scenes.

I, 
 
I try to perform a transition between the loadmainmenu.lua and mainmenu.lua files.

I do not understand why the transition (“fade effect”) is not functioning the first time it is executed but only after mainmenu.lua has called loadmainmenu back. 

 
the transition functions (inside enterScene) are the followings:

loadmainmenu:

function scene:enterScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: enterScene event")               loadingImage = display.newImageRect ( "loading.png", 480, 320)     loadingImage.x = 240; loadingImage.y = 160      screenGroup:insert(loadingImage)          local goToMenu = function()         storyboard.gotoScene ("mainmenu", "fade", 500)     end          myTimer = timer.performWithDelay (5000, goToMenu, 1)      end  

Inside mainmenu.lua I have

function scene:enterScene(event)          local screenGroup = self.view          print ("\n mainmenu: enterScene event")          local backgroundImage = display.newImageRect ("mainMenuBG.png", 480, 320)     backgroundImage.x = 240; backgroundImage.y = 160     screenGroup:insert (backgroundImage)               local playBtn          local onPlayTouch = function (event)         if event.phase == "release" then                          --audio.play (btnSound)             storyboard.gotoScene ("loadmainmenu", "fade", 300)                      end     end     playBtn = ui.newButton {              defaultSrc = "playbtn.png",         defaultX = 100,          defaultY = 100,          overSrc = "playbtn-over.png",         overX = 100,         overY = 100,         onEvent = onPlayTouch,         id = "PlayButton",         text = "",         font = "Helvetica",         textColor = { 255, 255, 255, 255 },         size = 16,          emboss = false     }      playBtn.x = 240; playBtn.y = 400     screenGroup:insert(playBtn)          btnAnim = transition.to (playBtn, { time=500, y=260, transition=easing.inOutExpo }) end  

You are creating your display objects in enterScene.  When the enterScene event fires, the scene is already transitioned on the screen.  The next time you come back the scene transitions because it already exists.   Your display objects should be created in the createScene() function.  enterScene() is a place to create native objects, objects not managed by storyboard, start timers, transitions, etc.

Rob

I tried to change the position of my display objects but nothing changes. Its like the transition options are not followed when called for the first time, although the transition time is respected. I even tried to define the transition options as a separate variable, but still no “fade” transition for the first time, and its works after, when back from the mainmennu scene.

loadingmainmenu.lua

local storyboard = require ("storyboard") local scene = storyboard.newScene() local loadingImage local myTimer local options = {     effect = "fade",     time = 1000,     params = {} } ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: createScene event")     --storyboard.removeScene ("mainmenu")     storyboard.removeScene ("main")     loadingImage = display.newImageRect ( "loading.png", 480, 320)     loadingImage.x = 240; loadingImage.y = 160      screenGroup:insert(loadingImage) end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: enterScene event")          --scene transition     local goToMenu = function()             storyboard.gotoScene ("mainmenu", options)         end                       myTimer =  timer.performWithDelay(1000, goToMenu, 1)               end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if myTimer then timer.cancel (myTimer);      end          print ("\n loadmainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy loadmainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

mainmenu.lua

local storyboard = require ("storyboard") local scene = storyboard.newScene() ui = require ("ui") local btnAnim --local btnSound = audio.loadsound ("btnSound.wav") ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          -- removing older scenes          storyboard.removeScene ("loadmainmenu")     print ("\n mainmenu: createScene event")      end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n mainmenu: enterScene event")          local backgroundImage = display.newImageRect ("mainMenuBG.png", 480, 320)     backgroundImage.x = 240; backgroundImage.y = 160     screenGroup:insert (backgroundImage)               local playBtn          local onPlayTouch = function (event)         if event.phase == "release" then             --audio.play (btnSound)             storyboard.gotoScene ("loadmainmenu", "fade", 300)                      end     end     playBtn = ui.newButton {              defaultSrc = "playbtn.png",         defaultX = 100,          defaultY = 100,          overSrc = "playbtn-over.png",         overX = 100,         overY = 100,         onEvent = onPlayTouch,         id = "PlayButton",         text = "",         font = "Helvetica",         textColor = { 255, 255, 255, 255 },         size = 16,          emboss = false     }      playBtn.x = 240; playBtn.y = 400     screenGroup:insert(playBtn)          btnAnim = transition.to (playBtn, { time=500, y=260, transition=easing.inOutExpo }) end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if btnAnim then transition.cancel (btnAnim); end                    print ("\n mainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy mainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

mainmenu is still creating things in enterScene.

Rob

Thank you for your response. But still, with this new code, the first transition is not made properly (but with a straight cut).

local storyboard = require ("storyboard") local scene = storyboard.newScene() local loadingImage local myTimer local options = {     effect = "fade",     time = 1000,     params = {} } ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: createScene event")     --storyboard.removeScene ("mainmenu")     storyboard.removeScene ("main")     loadingImage = display.newImageRect ( "loading.png", 480, 320)     loadingImage.x = 240; loadingImage.y = 160      screenGroup:insert(loadingImage)               --scene transition     local goToMenu = function()             storyboard.gotoScene ("mainmenu", options)         end              myTimer =  timer.performWithDelay(1000, goToMenu, 1)           end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: enterScene event")          --scene transition           end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if myTimer then timer.cancel (myTimer);      end          print ("\n loadmainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy loadmainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

In fact my problem was not in the mainmenu scene, but in the first transition fron loadingmainmenu.lua to mainmenu.lua

You are creating your display objects in enterScene.  When the enterScene event fires, the scene is already transitioned on the screen.  The next time you come back the scene transitions because it already exists.   Your display objects should be created in the createScene() function.  enterScene() is a place to create native objects, objects not managed by storyboard, start timers, transitions, etc.

Rob

I tried to change the position of my display objects but nothing changes. Its like the transition options are not followed when called for the first time, although the transition time is respected. I even tried to define the transition options as a separate variable, but still no “fade” transition for the first time, and its works after, when back from the mainmennu scene.

loadingmainmenu.lua

local storyboard = require ("storyboard") local scene = storyboard.newScene() local loadingImage local myTimer local options = {     effect = "fade",     time = 1000,     params = {} } ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: createScene event")     --storyboard.removeScene ("mainmenu")     storyboard.removeScene ("main")     loadingImage = display.newImageRect ( "loading.png", 480, 320)     loadingImage.x = 240; loadingImage.y = 160      screenGroup:insert(loadingImage) end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: enterScene event")          --scene transition     local goToMenu = function()             storyboard.gotoScene ("mainmenu", options)         end                       myTimer =  timer.performWithDelay(1000, goToMenu, 1)               end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if myTimer then timer.cancel (myTimer);      end          print ("\n loadmainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy loadmainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

mainmenu.lua

local storyboard = require ("storyboard") local scene = storyboard.newScene() ui = require ("ui") local btnAnim --local btnSound = audio.loadsound ("btnSound.wav") ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          -- removing older scenes          storyboard.removeScene ("loadmainmenu")     print ("\n mainmenu: createScene event")      end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n mainmenu: enterScene event")          local backgroundImage = display.newImageRect ("mainMenuBG.png", 480, 320)     backgroundImage.x = 240; backgroundImage.y = 160     screenGroup:insert (backgroundImage)               local playBtn          local onPlayTouch = function (event)         if event.phase == "release" then             --audio.play (btnSound)             storyboard.gotoScene ("loadmainmenu", "fade", 300)                      end     end     playBtn = ui.newButton {              defaultSrc = "playbtn.png",         defaultX = 100,          defaultY = 100,          overSrc = "playbtn-over.png",         overX = 100,         overY = 100,         onEvent = onPlayTouch,         id = "PlayButton",         text = "",         font = "Helvetica",         textColor = { 255, 255, 255, 255 },         size = 16,          emboss = false     }      playBtn.x = 240; playBtn.y = 400     screenGroup:insert(playBtn)          btnAnim = transition.to (playBtn, { time=500, y=260, transition=easing.inOutExpo }) end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if btnAnim then transition.cancel (btnAnim); end                    print ("\n mainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy mainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

mainmenu is still creating things in enterScene.

Rob

Thank you for your response. But still, with this new code, the first transition is not made properly (but with a straight cut).

local storyboard = require ("storyboard") local scene = storyboard.newScene() local loadingImage local myTimer local options = {     effect = "fade",     time = 1000,     params = {} } ----------------------------------------------------------------------------------------- function scene:createScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: createScene event")     --storyboard.removeScene ("mainmenu")     storyboard.removeScene ("main")     loadingImage = display.newImageRect ( "loading.png", 480, 320)     loadingImage.x = 240; loadingImage.y = 160      screenGroup:insert(loadingImage)               --scene transition     local goToMenu = function()             storyboard.gotoScene ("mainmenu", options)         end              myTimer =  timer.performWithDelay(1000, goToMenu, 1)           end ----------------------------------------------------------------------------------------- function scene:enterScene(event)          local screenGroup = self.view          print ("\n loadmainmenu: enterScene event")          --scene transition           end ----------------------------------------------------------------------------------------- function scene:exitScene(event)          if myTimer then timer.cancel (myTimer);      end          print ("\n loadmainmenu: exitScene event") end  ----------------------------------------------------------------------------------------- function scene:destroyScene(event)               print (( " destroy loadmainmenu's scene")) end  ----------------------------------------------------------------------------------------- scene:addEventListener ("createScene", scene) scene:addEventListener ("enterScene", scene) scene:addEventListener ("exitScene", scene) scene:addEventListener ("destroyScene", scene) return scene  

In fact my problem was not in the mainmenu scene, but in the first transition fron loadingmainmenu.lua to mainmenu.lua