I noticed a problem with the storyboard.getPrevious() command.
in my game i have a branching scenes, there they lead you to more then one other scene look at the example below,
Scene 1 takes you to Scene 2
Scene 2 takes you to scene3, Scene5 and Scene 7
Scene 5 takes you to scene 3
now the problem lies with the getPrevious() as it only store it once where you originally came from.
so if i take scene 1- scene2 - scene 3 it will see that scene 2 was previous to scene 3. and thats correct, but then lets go back to scene 2, then go to scene 5. from scene5 we enter scene 2 , it will output last scene was scene2, but in reality it was scene 5.
here is a sample of my code.
scene1.lua
---------------------------------------------------------------------------------
-- scene1 Room 1
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local lastScene = storyboard.getPrevious()
storyboard.health = require ("health")
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local background, room2,
local healthInfo = health.getInfo()
-- Touch event listener for background image
local function gotoRoom2( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene2", "fade", 400 )
return true
end
end
function scene:createScene( event )
local screenGroup = self.view
background = display.newImage( "assets/graphics/Room1.png", 0, 0 )
screenGroup:insert( background )
room2 = display.newImage( "assets/graphics/gotoRoom2.png", 175, 0 )
screenGroup:insert( room2 )
room2.touch = gotoRoom2
print( "\n1: createScene event")
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print( "1: enterScene event" )
-- remove previous scene's view
storyboard.purgeScene( lastScene )
print( "last scene was:", lastScene ) -- output: last scene name
-- Update Lua memory text display
room2:addEventListener( "touch", room2 )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print( "1: exitScene event" )
-- remove touch listener for image
room2:removeEventListener( "touch", room2 )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print( "((destroying scene 1's view))" )
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
scene2.lua
---------------------------------------------------------------------------------
-- scene2 ROOM 2
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local lastScene = storyboard.getPrevious()
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local background, room3, room5, room7
-- Touch event listener for background image
local function gotoRoom3( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene3", "fade", 400 )
return true
end
end
local function gotoRoom5( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene5", "fade", 400 )
return true
end
end
local function gotoRoom7( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene7", "fade", 400 )
return true
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local screenGroup = self.view
background = display.newImage( "assets/graphics/Room2.png", 0, 0 )
screenGroup:insert( background )
room3 = display.newImage( "assets/graphics/gotoRoom3.png", 5, 130 )
screenGroup:insert( room3 )
room3.touch = gotoRoom3
room5 = display.newImage( "assets/graphics/gotoRoom5.png", 175, 5 )
screenGroup:insert( room5 )
room5.touch = gotoRoom5
room7 = display.newImage( "assets/graphics/gotoRoom7.png", 350, 130 )
screenGroup:insert( room7 )
room7.touch = gotoRoom7
print( "\n2: createScene event")
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print( "2: enterScene event" )
-- remove previous scene's view
storyboard.purgeScene( lastScene )
print( "last scene was:", lastScene ) -- output: last scene name
-- Update Lua memory text display
room3:addEventListener( "touch", room3 )
room5:addEventListener( "touch", room5 )
room7:addEventListener( "touch", room7 )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print( "2: exitScene event" )
-- remove touch listener for image
room3:removeEventListener( "touch", room3 )
room5:removeEventListener( "touch", room5 )
room7:removeEventListener( "touch", room7 )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print( "((destroying scene 2's view))" )
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
scene5.lua
---------------------------------------------------------------------------------
-- scene5 Room 5
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local lastScene = storyboard.getPrevious()
storyboard.health = require ("health")
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local background, room3,
local healthInfo = health.getInfo()
-- Touch event listener for background image
local function gotoRoom3( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene3", "fade", 400 )
return true
end
end
function scene:createScene( event )
local screenGroup = self.view
background = display.newImage( "assets/graphics/Room5.png", 0, 0 )
screenGroup:insert( background )
room3 = display.newImage( "assets/graphics/gotoRoom3.png", 175, 0 )
screenGroup:insert( room3 )
room3.touch = gotoRoom3
print( "\n5: createScene event")
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print( "5: enterScene event" )
-- remove previous scene's view
storyboard.purgeScene( lastScene )
print( "last scene was:", lastScene ) -- output: last scene name
-- Update Lua memory text display
room3:addEventListener( "touch", room3 )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print( "5: exitScene event" )
-- remove touch listener for image
room3:removeEventListener( "touch", room3 )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print( "((destroying scene 5's view))" )
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
has anyone experienced this issue before? [import]uid: 17701 topic_id: 25991 reply_id: 325991[/import]