enterFrame proxy stops after re-going on a scene

Hello,

When leaving a scene, for witch there are an enterFrame listener object attached to an object, to an other scene, the Runtime continue to run, but stop when I come back, why ??

I explain :

–scene1–

local scene1 = composer.newScene() function scene1:create(event) local view=self.view local rect=display.newRect(view,0,0,300,300) rect:addEventListener("tap",function() composer.gotoScene("scene2") end) end scene1:addEventListener( "create", scene1 )

–scene2–

local scene2 = composer.newScene() function scene2:create(event) local view=self.view local rect=display.newRect(view,0,0,300,300) rect:addEventListener("tap",function() composer.gotoScene("scene1") end) local circ=display.newCircle(view,100,100,30) circ.enterFrame=function() circ.y=circ.y+1 end Runtime:addEventListener("enterFrame",circ) end scene2:addEventListener( "create", scene2)

So i arrive on scene1, then i click on the rectangle to go on scene2.

On scene 2 the circle began to move from top to bottom of the device, but when I switch to scene 1 , I know that the circle continue to drop, and when i re-enter on scene2, the Runtime stop to work !

I have tried this with a runtime working with a function, and there are no problem, but not with a table proxy.

Thanks, Yvan.

I’m also having this same problem

Hi Yvan, @phpedinei,

It’s highly recommended that you stop, pause or otherwise cancel actions that you don’t want to be continued when a scene goes offscreen. By default, the “create” block will only occur once, and not again when you return to the scene, so you shouldn’t do anything related to “starting the scene in motion or action” in that block… the “show” block is almost always better for that. So basically, in most cases, you should stop/pause/cancel things in the “hide > did” block, and then restart/resume things in the “show > will” phase.

Best regards,

Brent

Hi! @bjsorrentino

I have similar issue. Right now i play game in game.lua, when game is lost i go to endscreen.lua , but the enterframe from game.lua is still looping on the back. And when i try to destroy the scene(To start the game from the beginning), it gives me errors. 

In scene:show i call Runtime:addEventListener(“enterFrame”, enterframe). Where i need to call removeEventListener? 

function scene:show( event )

    local phase = event.phase

    if ( phase == “will” ) then

        Runtime:addEventListener( “enterFrame”, enterFrame )

    elseif ( phase == “did” ) then

    end

end

Hi,

During the “will” or “did” phase of hide scene, or when you lost the game, in a block of code.

function scene:hide( event ) local phase = event.phase if ( phase == "will" ) then Runtime:removeEventListener( "enterFrame", enterFrame ) elseif ( phase == "did" ) then end end

Thanks for answering!

I thought that’s the right place too. Still have problem, when the game is lost and i  use "composer.gotoScene(“refresh”), i still get this error:

“game\lib\player.lua:70: attempt to perform arithmetic on field ‘mass’ (a nil value)”

refresh.lua:

-- Requirements local composer = require( "composer" ) -- Vars/Objects local to scene local scene = composer.newScene() local prevScene = composer.getSceneName( "previous" ) local function reloadLvl() composer.removeScene(prevScene) composer.gotoScene("scene.endscreen") end timer.performWithDelay( 1000, reloadLvl) return scene

It seems like the player and also the enemy is still running in the game.lua , how to stop them?

You have to stop your Runtime enterFrame listeners before you leave your game scene. Once you remove the game scene, the listener is still running but the objects are not there and will give you this error.

Rob

I’m also having this same problem

Hi Yvan, @phpedinei,

It’s highly recommended that you stop, pause or otherwise cancel actions that you don’t want to be continued when a scene goes offscreen. By default, the “create” block will only occur once, and not again when you return to the scene, so you shouldn’t do anything related to “starting the scene in motion or action” in that block… the “show” block is almost always better for that. So basically, in most cases, you should stop/pause/cancel things in the “hide > did” block, and then restart/resume things in the “show > will” phase.

Best regards,

Brent

Hi! @bjsorrentino

I have similar issue. Right now i play game in game.lua, when game is lost i go to endscreen.lua , but the enterframe from game.lua is still looping on the back. And when i try to destroy the scene(To start the game from the beginning), it gives me errors. 

In scene:show i call Runtime:addEventListener(“enterFrame”, enterframe). Where i need to call removeEventListener? 

function scene:show( event )

    local phase = event.phase

    if ( phase == “will” ) then

        Runtime:addEventListener( “enterFrame”, enterFrame )

    elseif ( phase == “did” ) then

    end

end

Hi,

During the “will” or “did” phase of hide scene, or when you lost the game, in a block of code.

function scene:hide( event ) local phase = event.phase if ( phase == "will" ) then Runtime:removeEventListener( "enterFrame", enterFrame ) elseif ( phase == "did" ) then end end

Thanks for answering!

I thought that’s the right place too. Still have problem, when the game is lost and i  use "composer.gotoScene(“refresh”), i still get this error:

“game\lib\player.lua:70: attempt to perform arithmetic on field ‘mass’ (a nil value)”

refresh.lua:

-- Requirements local composer = require( "composer" ) -- Vars/Objects local to scene local scene = composer.newScene() local prevScene = composer.getSceneName( "previous" ) local function reloadLvl() composer.removeScene(prevScene) composer.gotoScene("scene.endscreen") end timer.performWithDelay( 1000, reloadLvl) return scene

It seems like the player and also the enemy is still running in the game.lua , how to stop them?

You have to stop your Runtime enterFrame listeners before you leave your game scene. Once you remove the game scene, the listener is still running but the objects are not there and will give you this error.

Rob