SceneShow isn't getting affected by the scene change effect.

My question is why isn’t scene:show getting affected by the scene change effect?

Heres the main.lua.

local composer = require( "composer" ) composer.gotoScene( "menu", { time = 1000, effect = "crossFade" } )

 And here is menu.lua.

local composer = require( "composer" ) local scene = composer.newScene() ------------------------------------------------------------------------------------------ centerX = display.contentCenterX centerY = display.contentCenterY actualH = display.actualContentHeight actualW = display.actualContentWidth ------------------------------------------------------------------------------------------ function scene:create( event ) local sceneGroup = self.view end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) then local BG = display.newRect( 0, 0, actualW, 120 ) BG.x = centerX BG.y = centerY - actualH/2 + 120/2 sceneGroup:insert(BG) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

If i put the BG image in the scene:create then it cross fades like normal but if its in the show then it doesnt show up until the transition is complete.

–SonicX278

This is because scene:show’s did phase, doesn’t execute until after the scene has already transitioned on the screen. Please create things in scene:create(). If you do not do this, you won’t get transitions.

Rob

But if i add things in scene create then scope wont see the functions in scene show.

–SonicX278

If you must create object under show and you would like the transition to work then create them under the phase “will”. This will give Corona time to create the objects, insert them into the sceneGroup and transition them correctly.

local composer = require( "composer" ) local scene = composer.newScene() ------------------------------------------------------------------------------------------ centerX = display.contentCenterX centerY = display.contentCenterY actualH = display.actualContentHeight actualW = display.actualContentWidth ------------------------------------------------------------------------------------------ function scene:create( event ) local sceneGroup = self.view end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then local BG = display.newRect( 0, 0, actualW, 120 ) BG.x = centerX BG.y = centerY - actualH/2 + 120/2 sceneGroup:insert(BG) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Alright i can do that. Thanks!

–SonicX278

If you’re having scope problems then you need to learn to solve the scope problems.

See: https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Variables, objects and functions that you need to access from both scene:create() and scene:show(), just predeclare the variable local at the top of the scene outside of any scene functions. Those variables, objects and functions will be scoped for the whole module when they are in the main chunk and not inside another function.

It may not seem like an important thing, but as write more and more complex code and as you start working with other developers and on development teams, coding work arounds will become a worse and worse practice.

Rob

It’s fine haha. I know scope really well.

–SonicX278

I’m really confused, if you know scope, then why are you saying you can’t use scene:create()?

Rob

Ahh sorry. Long story. I’m on my phone right now so don’t want to type it out. I will answer when i’m on my laptop.

–SonicX278

This is because scene:show’s did phase, doesn’t execute until after the scene has already transitioned on the screen. Please create things in scene:create(). If you do not do this, you won’t get transitions.

Rob

But if i add things in scene create then scope wont see the functions in scene show.

–SonicX278

If you must create object under show and you would like the transition to work then create them under the phase “will”. This will give Corona time to create the objects, insert them into the sceneGroup and transition them correctly.

local composer = require( "composer" ) local scene = composer.newScene() ------------------------------------------------------------------------------------------ centerX = display.contentCenterX centerY = display.contentCenterY actualH = display.actualContentHeight actualW = display.actualContentWidth ------------------------------------------------------------------------------------------ function scene:create( event ) local sceneGroup = self.view end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then local BG = display.newRect( 0, 0, actualW, 120 ) BG.x = centerX BG.y = centerY - actualH/2 + 120/2 sceneGroup:insert(BG) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Alright i can do that. Thanks!

–SonicX278

If you’re having scope problems then you need to learn to solve the scope problems.

See: https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Variables, objects and functions that you need to access from both scene:create() and scene:show(), just predeclare the variable local at the top of the scene outside of any scene functions. Those variables, objects and functions will be scoped for the whole module when they are in the main chunk and not inside another function.

It may not seem like an important thing, but as write more and more complex code and as you start working with other developers and on development teams, coding work arounds will become a worse and worse practice.

Rob

It’s fine haha. I know scope really well.

–SonicX278

I’m really confused, if you know scope, then why are you saying you can’t use scene:create()?

Rob

Ahh sorry. Long story. I’m on my phone right now so don’t want to type it out. I will answer when i’m on my laptop.

–SonicX278