Hello. I’m conducting an experiment for my app . I made a different file to test switching scenes on collision . When the collision happens in my test file the scene does not switch . However I do not have any errors pooping up . Here is my main.lua code :
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local physics = require( "physics" ) physics.start() physics.setGravity(0, 15) -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 ground.myName = "ground" physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) local crate = display.newImageRect( "crate.png", 90, 90 ) crate.x = 60 crate.y = 20 crate.rotation = 0 physics.addBody( crate, "dynamic" , { friction=0.5, bounce=0.3 } ) local function onCollision( self, event ) local other = event.other if( event.phase == "began" and self.isCrate and other.isGround ) then timer.performWithDelay( 30, function() composer.openScene( "restart.lua" ) end ) self:removeEventListener( "collision") end return true end crate.collision = onCollision crate:addEventListener( "collision" )
here is my restart.lua code :
local composer = require( "composer" ) local ground = display.newImage( "ground.png" ) ground.x = 200
Why is the scene not switching and what corrections do I need to make.
Thank you.