transition effect is not working, I need help!

–requires

local composer = require( “composer” )

local scene = composer.newScene()

local function gotoGame()

composer.gotoScene( “game”, { time=800, effect=“crossFade” } )

end

– background

local startb= display.newImageRect( “startb.png”, 575, 320 )

startb.x = 240

startb.y = 160

local name= display.newImageRect( “title.png”, 400, 100 )

name.x = 240

name.y = 60

local submarine= display.newImageRect( “submarinee.png”, 120, 90 )

submarine.x = 430

submarine.y = 100

local startbutton= display.newImageRect( “Startbutton.png”, 100, 45 )

startbutton.x = 250

startbutton.y = 150

startbutton:addEventListener( “tap”, gotoGame )

–  *************************Scene event functions**********************

– create()

function scene:create( event )

local sceneGroup = self.view

startb= display.newImageRect( “startb.png”, 575, 320 )

startb.x = 240

startb.y = 160

sceneGroup:insert( startb )

name= display.newImageRect( “title.png”, 400, 100 )

name.x = 240

name.y = 60

sceneGroup:insert( name )

submarine= display.newImageRect( “submarinee.png”, 120, 90 )

submarine.x = 430

submarine.y = 100

sceneGroup:insert( submarine )

startbutton= display.newImageRect( “Startbutton.png”, 100, 45 )

startbutton.x = 250

startbutton.y = 150

sceneGroup:insert( startbutton )

startbutton:addEventListener( “tap”, gotoGame)

end

–show

function scene:showScene( event )

local sceneGroup = self.view

local phase = event.phase

if ( phase == “will” ) then

– Code here runs when the scene is still off screen (but is about to come on screen)

elseif ( phase == “did” ) then

– Code here runs when the scene is entirely on screen

end

end

function scene:hideScene( event )

local sceneGroup = self.view

local phase = event.phase

if ( phase == “will” ) then

– Code here runs when the scene is on screen (but is about to go off screen)

elseif ( phase == “did” ) then

– Code here runs immediately after the scene goes entirely off screen

end

end

–destroy()

function scene:destroyScene( event )

local sceneGroup = self.view

end

scene:addEventListener(“createScene”, scene)

scene:addEventListener(“showScene”, scene)

scene:addEventListener(“hideScene”, scene)

scene:addEventListener(“destroyScene”, scene)

return scene

Is this your main.lua?

 

--requires local composer = require( "composer" ) local scene = composer.newScene() local function gotoGame() composer.gotoScene( "game", { time=800, effect="crossFade" } ) end -- background local startb= display.newImageRect( "startb.png", 575, 320 ) startb.x = 240 startb.y = 160 local name= display.newImageRect( "title.png", 400, 100 ) name.x = 240 name.y = 60 local submarine= display.newImageRect( "submarinee.png", 120, 90 ) submarine.x = 430 submarine.y = 100 local startbutton= display.newImageRect( "Startbutton.png", 100, 45 ) startbutton.x = 250 startbutton.y = 150 startbutton:addEventListener( "tap", gotoGame )

If so, main.lua is never a scene itself. And objects created in main.lua will stay on top of any composer managed scenes.

Rob

This is not my main.lua file, it’s another file that it’s linked to the main.lua

What of the code you posted is owned by game.lua?


– game.lua


–requires

local physics = require “physics”

physics.start()

local composer = require( “composer” )

local scene = composer.newScene()

– background

local background= display.newImageRect( “background.png”, 575, 320 )

background.x = 240

background.y = 160

local background2= display.newImageRect( “background.png”, 575, 320 )

background2.x = 800

background2.y = 160

local submarine= display.newImageRect( “submarinee.png”, 90, 70 )

submarine.x = 40

submarine.y = 140

physics.addBody(submarine, “dynamic”, {density=.3, bounce=0.1, friction=.2, radius=45})

function scrollCity(self,event)

if self.x < -320 then

self.x = 800

else

self.x = self.x - 2

end

end

function activateSub(self,event)

self:applyForce(0, -100, self.x, self.y)

end

function touchScreen(event)

if event.phase == “began” then

 --print(“touch”)

 submarine.enterFrame = activateSub

 Runtime:addEventListener(“enterFrame”, submarine)

end

if event.phase == “ended” then

 Runtime:removeEventListener(“enterFrame”, submarine)

end

end

Runtime:addEventListener(“touch”, touchScreen)

background.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background)

background2.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background2)

–  *************************Scene event functions**********************

– create()

function scene:create( event )

local sceneGroup = self.view

   physics.pause()  – Temporarily pause the physics engine

background= display.newImageRect( sceneGroup, “background.png”, 575, 320 )

background.x = 240

background.y = 160

background2= display.newImageRect( sceneGroup, “background.png”, 575, 320 )

background2.x = 800

background2.y = 160

submarine= display.newImageRect( sceneGroup, “submarinee.png”, 90, 70 )

submarine.x = 40

submarine.y = 140

physics.addBody(submarine, “dynamic”, {density=.3, bounce=0.1, friction=.2, radius=45})

end

–show

function scene:showScene( event )

local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Code here runs when the scene is still off screen (but is about to come on screen)

    elseif ( phase == “did” ) then

        – Code here runs when the scene is entirely on screen

  end

  Runtime:addEventListener(“touch”, touchScreen)

  background.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background)

  background2.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background2)

end

–hide()

function scene:hideScene( event )

local sceneGroup = self.view

end

function scene:destroyScene( event )

local sceneGroup = self.view

end

scene:addEventListener(“createScene”, scene)

scene:addEventListener(“showScene”, scene)

scene:addEventListener(“hideScene”, scene)

scene:addEventListener(“destroyScene”, scene)

return scene

Well for a start every asset used in a scene should be created inside scene:create() and inserted into sceneGroup.  This is so all objects are properly cleaned when the scene is removed and physics.start() should not be called until scene:show().

If you don’t structure your scene properly then it can’t be transitioned properly.

scene:create() = create all objects

scene:show() = begin all animations, assign physics, etc. 

Why do background and background 2 have events? either combine the assets into a single file or if you must insert them into a display group and add the event to that instead.

I think maybe you misunderstand what enterFrame() is for… there should only really be 1 per scene and that should handle all per frame events.  e.g. why is activateSub and enterFrame event if it only happens once?  This should be in scene:show()

Basically if you don’t structure your scene code correctly then nothing will work as expected.

Thanks a lot, I will try to correct my structure and see if it works

Is this your main.lua?

 

--requires local composer = require( "composer" ) local scene = composer.newScene() local function gotoGame() composer.gotoScene( "game", { time=800, effect="crossFade" } ) end -- background local startb= display.newImageRect( "startb.png", 575, 320 ) startb.x = 240 startb.y = 160 local name= display.newImageRect( "title.png", 400, 100 ) name.x = 240 name.y = 60 local submarine= display.newImageRect( "submarinee.png", 120, 90 ) submarine.x = 430 submarine.y = 100 local startbutton= display.newImageRect( "Startbutton.png", 100, 45 ) startbutton.x = 250 startbutton.y = 150 startbutton:addEventListener( "tap", gotoGame )

If so, main.lua is never a scene itself. And objects created in main.lua will stay on top of any composer managed scenes.

Rob

This is not my main.lua file, it’s another file that it’s linked to the main.lua

What of the code you posted is owned by game.lua?


– game.lua


–requires

local physics = require “physics”

physics.start()

local composer = require( “composer” )

local scene = composer.newScene()

– background

local background= display.newImageRect( “background.png”, 575, 320 )

background.x = 240

background.y = 160

local background2= display.newImageRect( “background.png”, 575, 320 )

background2.x = 800

background2.y = 160

local submarine= display.newImageRect( “submarinee.png”, 90, 70 )

submarine.x = 40

submarine.y = 140

physics.addBody(submarine, “dynamic”, {density=.3, bounce=0.1, friction=.2, radius=45})

function scrollCity(self,event)

if self.x < -320 then

self.x = 800

else

self.x = self.x - 2

end

end

function activateSub(self,event)

self:applyForce(0, -100, self.x, self.y)

end

function touchScreen(event)

if event.phase == “began” then

 --print(“touch”)

 submarine.enterFrame = activateSub

 Runtime:addEventListener(“enterFrame”, submarine)

end

if event.phase == “ended” then

 Runtime:removeEventListener(“enterFrame”, submarine)

end

end

Runtime:addEventListener(“touch”, touchScreen)

background.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background)

background2.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background2)

–  *************************Scene event functions**********************

– create()

function scene:create( event )

local sceneGroup = self.view

   physics.pause()  – Temporarily pause the physics engine

background= display.newImageRect( sceneGroup, “background.png”, 575, 320 )

background.x = 240

background.y = 160

background2= display.newImageRect( sceneGroup, “background.png”, 575, 320 )

background2.x = 800

background2.y = 160

submarine= display.newImageRect( sceneGroup, “submarinee.png”, 90, 70 )

submarine.x = 40

submarine.y = 140

physics.addBody(submarine, “dynamic”, {density=.3, bounce=0.1, friction=.2, radius=45})

end

–show

function scene:showScene( event )

local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Code here runs when the scene is still off screen (but is about to come on screen)

    elseif ( phase == “did” ) then

        – Code here runs when the scene is entirely on screen

  end

  Runtime:addEventListener(“touch”, touchScreen)

  background.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background)

  background2.enterFrame = scrollCity

Runtime:addEventListener(“enterFrame”, background2)

end

–hide()

function scene:hideScene( event )

local sceneGroup = self.view

end

function scene:destroyScene( event )

local sceneGroup = self.view

end

scene:addEventListener(“createScene”, scene)

scene:addEventListener(“showScene”, scene)

scene:addEventListener(“hideScene”, scene)

scene:addEventListener(“destroyScene”, scene)

return scene

Well for a start every asset used in a scene should be created inside scene:create() and inserted into sceneGroup.  This is so all objects are properly cleaned when the scene is removed and physics.start() should not be called until scene:show().

If you don’t structure your scene properly then it can’t be transitioned properly.

scene:create() = create all objects

scene:show() = begin all animations, assign physics, etc. 

Why do background and background 2 have events? either combine the assets into a single file or if you must insert them into a display group and add the event to that instead.

I think maybe you misunderstand what enterFrame() is for… there should only really be 1 per scene and that should handle all per frame events.  e.g. why is activateSub and enterFrame event if it only happens once?  This should be in scene:show()

Basically if you don’t structure your scene code correctly then nothing will work as expected.

Thanks a lot, I will try to correct my structure and see if it works