Use a common background in different scenes - Composer

Hello,

I want to use a common background in 2 scenes.

What I mean is:

Game starts –> Mainscreen (bg1 {fixed}) –> PLAYSCREEN (bg1 or bg2{randomizing 2 backgrounds}) --> gameover screen (bg1 or bg2 {this should be same as background of playscreen}) –> PLAYSCREEN (and cycle continues)…

Now, suppose (bg1) comes up in playscreen. So how can I use the same background (i.e bg1) in gameover screen? {Same goes for bg2)

Why not just load the background in each scene’s scene:create() function?

I thought of doing the same. But how can I load the same background in gameover screen?
I mean, I have randomized 2 backgrounds in playscreen window. Suppose (bg1) loads up in playscreen …
So in this case I want same bg1 in gameover screen too …
And the same is for (bg2).

http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Store the background image name in a table that’s shared between the scenes.  You could also store a variable in the Composer object in your game scene and retrieve it in your game over scene:

http://docs.coronalabs.com/api/library/composer/setVariable.html

http://docs.coronalabs.com/api/library/composer/getVariable.html

You could also pass the file name as a parameter on the composer.gotoScene() call:

http://docs.coronalabs.com/api/library/composer/gotoScene.html

See the “params” option on the options table.

Rob

Thank you :slight_smile:
Using setVariable and getVariable method was quite easy :slight_smile:

Why not just load the background in each scene’s scene:create() function?

I thought of doing the same. But how can I load the same background in gameover screen?
I mean, I have randomized 2 backgrounds in playscreen window. Suppose (bg1) loads up in playscreen …
So in this case I want same bg1 in gameover screen too …
And the same is for (bg2).

http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Store the background image name in a table that’s shared between the scenes.  You could also store a variable in the Composer object in your game scene and retrieve it in your game over scene:

http://docs.coronalabs.com/api/library/composer/setVariable.html

http://docs.coronalabs.com/api/library/composer/getVariable.html

You could also pass the file name as a parameter on the composer.gotoScene() call:

http://docs.coronalabs.com/api/library/composer/gotoScene.html

See the “params” option on the options table.

Rob

Thank you :slight_smile:
Using setVariable and getVariable method was quite easy :slight_smile: