Gotcha!
I give code that I use for myself.
The idea is to have a so-called “transition scene”, in other words YOU CANNOT go from scene A to scene A, instead you can go to scene A to scene B and go back to scene A.
- Create a transition scene something like “transition.lua” the code is simple:
--
-- EMPTY SCENE to organase transitions between the pages
local scene = composer.newScene()
composer.recycleOnSceneChange = true
local tmp_str_a = composer.getSceneName("previous")
if tmp_str_a ~= nil then
composer.removeScene(tmp_str_a)
end
----------
function scene:create(event)
local phase = event.phase
local sceneGroup = self.view
end
function scene:show(event)
local phase = event.phase
if phase == "will" then
elseif phase == "did" then
local the_effect_str = composer.getVariable("effect")
local scene2go_str = composer.getVariable("scene")
local time_int = composer.getVariable("time")
if time_int == nil then
time_int = 200
end
-- cleaning up
composer.setVariable("scene", nil)
composer.setVariable("effect", nil)
composer.setVariable("time", nil)
composer.gotoScene(scene2go_str, {effect = the_effect_str, time = time_int})
end
end
function scene:hide(event)
local phase = event.phase
if event.phase == "will" then
elseif phase == "did" then
end
end
function scene:destroy(event)
local sceneGroup = self.view
local phase = event.phase
end
-- Listener setup
scene:addEventListener("create", scene)
scene:addEventListener("show", scene)
scene:addEventListener("hide", scene)
scene:addEventListener("destroy", scene)
return scene
- anywhere in your scene A when you need to realod it, use the following code:
composer.setVariable(“effect”, “crossFade”)
composer.setVariable(“scene”, “YOUR_SCENE_TO_RELOAD”)
composer.setVariable(“time”, 200)
composer.gotoScene(“transition”, {time = 0}) – transition.lua
I hope the code is self-explanatory for you 