Question about elements .

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.

I think the elements being referred to are the different elements of a multi-element physics body. You can read about that in the docs here. In any case, your crate and ground are single-element bodies, so you don’t need to worry about that.

A couple of points that might help you out:

When you create something like crate or ground, they don’t automatically come with properties like isCrate and isGround, you need to specify those yourself.

There is no mention in the composer docs about “composer.openScene()”, what your looking for has a different name. The docs for composer are here. There’s a list of composer functions on the left, the one you’re looking for is the fourth one down.

I think the elements being referred to are the different elements of a multi-element physics body. You can read about that in the docs here. In any case, your crate and ground are single-element bodies, so you don’t need to worry about that.

A couple of points that might help you out:

When you create something like crate or ground, they don’t automatically come with properties like isCrate and isGround, you need to specify those yourself.

There is no mention in the composer docs about “composer.openScene()”, what your looking for has a different name. The docs for composer are here. There’s a list of composer functions on the left, the one you’re looking for is the fourth one down.