composer switch to another scene i can't see the background of the next scene

hi,

i have a lot of difficulties with composer…it’s not so easy!

my previous scene is “game” (game.lua) everything is ok 

when i go to my scene “recolt” with this snippet inside my game lua :

local function goTo()    print("gotoscene")     composer.gotoScene( "recolt", { time = 1000, effect = "fromRight", params = para ms } ) end timer.performWithDelay( 1000, goTo )

the problem is that i see my previous scene behind my recolt scene and i can’t see my background but i see my circle who’s moving ??? however my sceneGroup is correct :

sceneGroup:insert(background,circle)

when i do : 

sceneGroup:insert(circle,background) 

i see my background who hide my previous scene and my circle. > behavior expected

What’s wrong? i would like to see my background and my circle in y “recolt” scene. Could you help me ? below the snippet “recolt.lua”.

--recolt.lua local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event )     local sceneGroup = self.view     params = event.params local background=display.newImageRect("back02.png",display.contentWidth\*.5,d isplay.contentHeight\*.5,320,480)         background.x,background.y=display.contentWidth\*.5,display.contentHeight\*.5         background.xScale,background.yScale=2,2         background.alpha=1         local circle = display.newCircle(120,100,100)     sceneGroup:insert(background,circle) timeT=150 local function tr4() transition.to(circle,{time=timeT,x=200,y=300,alpha=1,transition=easing.linear, xScale=1,yScale=1}) end local function tr3() transition.to(circle,{time=200,x=100,y=300,transition=easing.linear, xScale=.2 ,yScale=.5,onComplete=tr4}) end local function tr2() transition.to(circle,{time=200,x=200,y=295,transition=easing.linear, xScale=.2 ,yScale=.2,alpha=.2,onComplete=tr3}) end local function tr1() transition.to(circle,{time=timeT,x=300,y=300,transition=easing.linear, xScale= .5,yScale=.5,onComplete=tr2}) end timer.performWithDelay(700,tr1,-1) end function scene:show( event )     local sceneGroup = self.view     params = event.params     if event.phase == "did" then         --physics.start()     end end function scene:hide( event )     local sceneGroup = self.view         if event.phase == "will" then         --         -- Remove enterFrame listeners here         --         --physics.stop()     end end function scene:destroy( event )     local sceneGroup = self.view     end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

another thing wen i paste my text from sublime text to the forum, i loss some part of my code formatting ?

Ok so i looked over your code and its very difficult to understand… so i got your whole code and just cleaned it up and made it like i would code it… please don’t take this as an insult… here’s the revised code … if you still have the problem please explain it thoroughly and ill help

--recolt.lua local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImageRect( "back02.png", display.contentWidth\*.5, display.contentHeight \* .5 , 320, 480 ) background.x = display.contentWidth \* .5 background.y = display.contentHeight \* .5 background.xScale = 2 background.yScale = 2 background.alpha = 1 local circle = display.newCircle(120,100,100) sceneGroup:insert(background) sceneGroup:insert(circle) timeT=150 local function tr4() transition.to( circle, { time = timeT, x = 200, y = 300, alpha = 1, transition = easing.linear, xScale = 1, yScale = 1 } ) end local function tr3() transition.to( circle, { time = 200, x = 100, y = 300, transition = easing.linear, xScale = .2, yScale=.5, onComplete = tr4 } ) end local function tr2() transition.to( circle, { time = 200, x = 200, y = 295, transition = easing.linear, xScale=.2, yScale = .2, alpha = .2, onComplete = tr3 } ) end local function tr1() transition.to( circle, { time = timeT, x = 300, y = 300, transition = easing.linear, xScale = .5, yScale = .5, onComplete = tr2 } ) end timer.performWithDelay( 700, tr1, -1 ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then --physics.start() end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then -- -- Remove enterFrame listeners here -- --physics.stop() end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

I also use sublime so you should see exactly what i did…

hi,

I copy paste your revised code. Now when i go to “recolt” scene, my previous scene is always present and I can not see my circle and my background from my recolt scene. 

I tested with my game.lua simplifying and i have still the problem when i switch . The problem is probably in my groups .
This is the file “game.lua” that leads to recolt.lua.

Where is my mistake?

------------------------------------------------------------------ -- game.lua ------------------------------------------------------------------ local composer = require("composer") local physics =  require("physics") local widget = require( "widget" ) local scene = composer.newScene() local function goTo()     print("gotoscene")     composer.gotoScene( "recolt", { time = 1000, effect = "fromRight", params = params } ) end timer.performWithDelay( 1000, goTo ) function scene:create( event ) local sceneGroup = self.view local myGroupBackground = display.newGroup() local myGroupCharacter = display.newGroup()     local background2=display.newImageRect(myGroupBackground, "back04.png",display.contentWidth\*.5,display.contentHeight\*.5,sidexdisplayenlarge,sideydisplayenlarge)     background2.x,background2.y=display.contentWidth\*.5,display.contentHeight\*.5     background2.xScale,background2.yScale=2,2     background2.alpha=1     local character=display.newImageRect(myGroupCharacter,"glass.png",display.contentWidth\*.5,display.contentHeight\*.5,sidexdisplayenlarge,sideydisplayenlarge)     character.x,character.y=display.contentWidth\*.5,display.contentHeight\*.5     character.xScale,character.yScale=2,2     character.alpha=1     sceneGroup:insert(myGroupBackground,myGroupCharacter) end function scene:show( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then       -- Called when the scene is still off screen (but is about to come on screen).    elseif ( phase == "did" ) then       -- Called when the scene is now on screen.       -- Insert code here to make the scene come alive.       -- Example: start timers, begin animation, play audio, etc.    end end -- "scene:hide()" function scene:hide( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then       -- Called when the scene is on screen (but is about to go off screen).       -- Insert code here to "pause" the scene.       -- Example: stop timers, stop animation, stop audio, etc.    elseif ( phase == "did" ) then       -- Called immediately after scene goes off screen.    end end -- "scene:destroy()" function scene:destroy( event )    local sceneGroup = self.view    -- Called prior to the removal of scene's view ("sceneGroup").    -- Insert code here to clean up the scene.    -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

You cannot insert multiple things into a group like:

sceneGroup:insert(a, b, c)

Instead you have to do:

sceneGroup:insert( a )

sceneGroup:insert( b )

sceneGroup:insert( c )

The others you specify after the comma are ignored.

Rob

You do you sceneGroup:insert(object) incorrect… you cant have multiple things on one scene group… it has to be it separate ones… like this for your game.lua 

Not this - sceneGroup:insert(myGroupBackground,myGroupCharacter) But this - sceneGroup:insert(myGroupBackground) sceneGroup:insert(myGroupCharacter)

hi Rob,

It’s funny i have find the solution and the same time i see a mail with rob miracle.

Thanks it was my error now everything works.

thanks also SonicX278.

ps when i copy paste a code from sublime to the forum, multiple blank line appears and i have to remove it.

i’am from mac…maybe the problem ?

Probably, maybe we have different versions? 

sublime text 2

Sublime Text 3

Ok so i looked over your code and its very difficult to understand… so i got your whole code and just cleaned it up and made it like i would code it… please don’t take this as an insult… here’s the revised code … if you still have the problem please explain it thoroughly and ill help

--recolt.lua local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view params = event.params local background = display.newImageRect( "back02.png", display.contentWidth\*.5, display.contentHeight \* .5 , 320, 480 ) background.x = display.contentWidth \* .5 background.y = display.contentHeight \* .5 background.xScale = 2 background.yScale = 2 background.alpha = 1 local circle = display.newCircle(120,100,100) sceneGroup:insert(background) sceneGroup:insert(circle) timeT=150 local function tr4() transition.to( circle, { time = timeT, x = 200, y = 300, alpha = 1, transition = easing.linear, xScale = 1, yScale = 1 } ) end local function tr3() transition.to( circle, { time = 200, x = 100, y = 300, transition = easing.linear, xScale = .2, yScale=.5, onComplete = tr4 } ) end local function tr2() transition.to( circle, { time = 200, x = 200, y = 295, transition = easing.linear, xScale=.2, yScale = .2, alpha = .2, onComplete = tr3 } ) end local function tr1() transition.to( circle, { time = timeT, x = 300, y = 300, transition = easing.linear, xScale = .5, yScale = .5, onComplete = tr2 } ) end timer.performWithDelay( 700, tr1, -1 ) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then --physics.start() end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then -- -- Remove enterFrame listeners here -- --physics.stop() end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

I also use sublime so you should see exactly what i did…

hi,

I copy paste your revised code. Now when i go to “recolt” scene, my previous scene is always present and I can not see my circle and my background from my recolt scene. 

I tested with my game.lua simplifying and i have still the problem when i switch . The problem is probably in my groups .
This is the file “game.lua” that leads to recolt.lua.

Where is my mistake?

------------------------------------------------------------------ -- game.lua ------------------------------------------------------------------ local composer = require("composer") local physics =  require("physics") local widget = require( "widget" ) local scene = composer.newScene() local function goTo()     print("gotoscene")     composer.gotoScene( "recolt", { time = 1000, effect = "fromRight", params = params } ) end timer.performWithDelay( 1000, goTo ) function scene:create( event ) local sceneGroup = self.view local myGroupBackground = display.newGroup() local myGroupCharacter = display.newGroup()     local background2=display.newImageRect(myGroupBackground, "back04.png",display.contentWidth\*.5,display.contentHeight\*.5,sidexdisplayenlarge,sideydisplayenlarge)     background2.x,background2.y=display.contentWidth\*.5,display.contentHeight\*.5     background2.xScale,background2.yScale=2,2     background2.alpha=1     local character=display.newImageRect(myGroupCharacter,"glass.png",display.contentWidth\*.5,display.contentHeight\*.5,sidexdisplayenlarge,sideydisplayenlarge)     character.x,character.y=display.contentWidth\*.5,display.contentHeight\*.5     character.xScale,character.yScale=2,2     character.alpha=1     sceneGroup:insert(myGroupBackground,myGroupCharacter) end function scene:show( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then       -- Called when the scene is still off screen (but is about to come on screen).    elseif ( phase == "did" ) then       -- Called when the scene is now on screen.       -- Insert code here to make the scene come alive.       -- Example: start timers, begin animation, play audio, etc.    end end -- "scene:hide()" function scene:hide( event )    local sceneGroup = self.view    local phase = event.phase    if ( phase == "will" ) then       -- Called when the scene is on screen (but is about to go off screen).       -- Insert code here to "pause" the scene.       -- Example: stop timers, stop animation, stop audio, etc.    elseif ( phase == "did" ) then       -- Called immediately after scene goes off screen.    end end -- "scene:destroy()" function scene:destroy( event )    local sceneGroup = self.view    -- Called prior to the removal of scene's view ("sceneGroup").    -- Insert code here to clean up the scene.    -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

You cannot insert multiple things into a group like:

sceneGroup:insert(a, b, c)

Instead you have to do:

sceneGroup:insert( a )

sceneGroup:insert( b )

sceneGroup:insert( c )

The others you specify after the comma are ignored.

Rob

You do you sceneGroup:insert(object) incorrect… you cant have multiple things on one scene group… it has to be it separate ones… like this for your game.lua 

Not this - sceneGroup:insert(myGroupBackground,myGroupCharacter) But this - sceneGroup:insert(myGroupBackground) sceneGroup:insert(myGroupCharacter)

hi Rob,

It’s funny i have find the solution and the same time i see a mail with rob miracle.

Thanks it was my error now everything works.

thanks also SonicX278.

ps when i copy paste a code from sublime to the forum, multiple blank line appears and i have to remove it.

i’am from mac…maybe the problem ?

Probably, maybe we have different versions? 

sublime text 2