composer goToScene effect=slideUp get the current state of the previous scene ?

hello :wink:

The behavior of the snippets below is : main.lua>scene1.lua>scene2.lua>scene1.lua

I don’t find the solution to do this :

in my scene1.lua i have random variable (a square who move randomly and the background color who change also randomly). when after going to scene2, my scene1 is empty ?

i use the effect “slideUp” to go to the scene2 who pushes current scene off by the documentation.

But how to return to scene1 with the same effect and get the previous state of this scene (scene1) because the values are random ???

Thanks if you can enlighten me :slight_smile:

my main.lua

--main.lua local composer = require( "composer" )composer.gotoScene( "scene1", { time =1000, effect = "fade"} )

my scene1.lua

local composer = require( "composer" ) local scene = composer.newScene() local wallpaper={} local square={} local function goToScene2()   composer.gotoScene( "scene2", { time =1000, effect = "slideUp"} ) end timer.performWithDelay(3000,goToScene2) -- "scene:create()" function scene:create( event )     local sceneGroup = self.view     wallpaper=display.newRect(display.contentWidth\*.5,display.contentHeight\*.5,display.contentWidth,display.contentHeight)     sceneGroup:insert(wallpaper)     square=display.newRect(200,200,50,50)     square:setFillColor(0,0,0)     sceneGroup:insert(square)     local function randomTransitionTosquare()     direction=math.random(10,300)     transition.to(square,{time=500,x=direction})     end     timer.performWithDelay( 501, randomTransitionTosquare,-1)          local function randomColorForWallpaper()       color1=math.round(math.random(0,1))       color2=math.round(math.random(0,1))       color3=math.round(math.random(0,1))       print(color)       wallpaper:setFillColor(color1,color2,color3)     end     timer.performWithDelay(500,randomColorForWallpaper,-1) end function scene:show( event )     local sceneGroup = self.view     local phase = event.phase     local value=event.params     if ( phase == "will" ) then     elseif ( phase == "did" ) then    end end function scene:hide( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then    elseif ( phase == "did" ) then    end end function scene:destroy( event )    local sceneGroup = self.view end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

myscene2.lua

local composer = require( "composer" ) local scene = composer.newScene() local wallpaper={} local function goToScene1()   composer.gotoScene( "scene1", { time =1000, effect = "slideDown"} ) end timer.performWithDelay( 1000, goToScene1) -- "scene:create()" function scene:create( event )     local sceneGroup = self.view     wallpaper=display.newRect(display.contentWidth\*.5,display.contentHeight\*.5,display.contentWidth,display.contentHeight)     wallpaper:setFillColor(1,0,0)     sceneGroup:insert(wallpaper) end function scene:show( event )    local sceneGroup = self.view     local phase = event.phase     local value=event.params     if ( phase == "will" ) then     elseif ( phase == "did" ) then    end end function scene:hide( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then    elseif ( phase == "did" ) then    end end function scene:destroy( event )    local sceneGroup = self.view end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene