但,如果是要重新載入目前的場景呢?
我們一樣可以呼叫composer.gotoScene( xxx ),其中xxx只要傳入目前場景的名稱即可,
不過,你會發現重新載入時,
scene:create()並沒有被呼叫到,
而是直接跳到scene:show(),
當然,你可以把scene:create()應該做的事移到scene:show()內去,
但這樣會變成scene:create()其實是多餘的,
之前可以透過storyboard.reloadScene()來重新載入,
目前新的Corona SDK已經不支援了,
要如何處理呢?
有一個簡單的方法,就是建一個暫時的轉換場景,
先呼叫它,然後再轉換回來:
local options = { effect = "fade", time = 0, params = { myData = 1234 } } composer.gotoScene( "RestartDummy", options )參數time可以設為0,表示立刻轉換,
params是我們想要傳給"RestartDummy"的參數,
"RestartDummy.lua"部份:
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) print( "((create scene RestartDummy's view))" ) local params = event.params print(params.myData) end --function scene:create( event ) function scene:show( event ) local phase = event.phase if "did" == phase then print( "((show scene RestartDummy's view))" ) composer.removeScene( xxx ) composer.gotoScene( "xxx", "fade", 0 ) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "((hiding scene RestartDummy's view))" ) end end function scene:destroy( event ) print( "((destroying scene RestartDummy's view))" ) end -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
沒有留言:
張貼留言