display.setDefault remains between scenes

Hello!
I have two scenes. The background color of each is different. When I enter a scene, the background color is applied to another scene.

scene1:
.
.
.
function scene:create( event )
local sceneGroup = self.view
display.setDefault( “background”,0.89,0.56,0.27)
end
.
.
.

scene2:

.
.
.
function scene:create( event )
local sceneGroup = self.view
display.setDefault( “background”,0.1,1,0.57)
end
.
.
.

How to preserve the different background color of each scene?

scene:create() method is only run when the scene is created. Unless you explicitly remove the scene, it won’t be recreated again, but instead it’ll just get “shown” again, see scene:show().

If you want to change the background colour every time you enter a scene, then you need to put that code inside scene:show(), within either the “will” or “did” phase.

You can learn more from the Composer guide: https://docs.coronalabs.com/guide/system/composer/index.html

1 Like

The problem is now solved. Thank you :+1: