I am trying to switch scene on collision in my app . I have looked at this tutorial :
https://docs.coronalabs.com/daily/api/event/collision/index.html
It says something about elements and it explains it but I don’t really get the explanation .And it also doesn’t tell how to switch scene on collision .
What is elements in a simpler explanation?
And what do I add to the code in the link to make it switch scene on collision ?
If you need it this is my code I have now( main.lua {am not getting results with this 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 ) print("create initialized? ", crate ) 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" )
restart.lua :
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 group:insert(logo) group:insert(ground) scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )
Thank you.