Scene management corona sdk

My game is simple but I dont understand the composer management.In this game spawndown 3 objects and we collect ones if we touch other objects game is over and go to scene main menu.

 My question is  how can restart the game when the player game over.here is my game.lua code

local composer = require( "composer" ) local scene = composer.newScene() --local widget = require ("widget") local physics= require("physics") physics:start() display.setStatusBar( display.HiddenStatusBar ) ------------------------------------------ --EKRAN AYARLARI--- -------------------------------------- centerX=display.contentCenterX centerY=display.contentCenterY screenLeft=display.screenOriginX screenWidth=display.contentWidth - screenLeft \* 2 screenRight=screenLeft + screenWidth screenTop=display.screenOriginY screenHeight=display.contentHeight - screenTop \* 2 screenBottom=screenTop + screenHeight display.contentWidht=screenWidth display.contentHeight=screenHeight ---------------------------------------------------------- ----Kullanılan parametreler -------------------------------------------------- local muzik = audio.loadSound('ses.wav') local alertView local Nart local cim local score = 0 local scoreText local pileUp=false local mRandom =math.random local mAbs =math.abs local objects = {"gubate" ,"hamburger","hotdog"} local restartButtton local physicsData = (require "shapedefs").physicsData(1.0)-- ------------------------------------------------------------------------------ -------------gameover alert kısmı ------------------------- local function alert(action ) if (action == 'lose') then alertView = display.newImage('resimler/gameover2.png') alertView.y =display.contentCenterY+20 alertView.x=centerX Nart.alpha =0 -- timer.cancel( spawntimer ) timer.performWithDelay(10, function() physics.stop() end, 1) scoreText = display.newText( "Score: " .. score, centerX,display.contentCenterY+50, native.systemFont,30 ) scoreText:setTextColor( 0, 255 ,255 ) end end ------------------------------------------------------------------------------ -------------------Obje olusturma ve Düşürme ---------------------------------- local function spawnObject () local objIdx = mRandom(#objects) local objName = objects[objIdx] local object = display.newImage ( "resimler/object\_" ..objName .. ".png") object.x=mRandom(screenLeft+30,screenRight-30) object.y=screenTop object.rotation=mRandom(-15,15) if objIdx \< 2 then object.type="food" else object.type="other" end physics.start( ) physics.addBody( object) physics.addBody( object ,"dynamic", physicsData:get("object\_" .. objName) )-- cim:toFront () end ------------------------------------------------------------------------------ ------------------------------------------------------------------------ ---Hareket ettirme fonksiyonu--- local function moveNart (event) if event.phase =="began" then local speed =1200/screenWidth \*(mAbs(Nart.x- event.x)) transition.to( Nart, {time=speed ,x = event.x}) end end --------------------------------------------------------------------------- ---------------------------------------------------------------------------- --collision olusturma ---- local function NartCollision(self , event) if event.phase =="began" then if event.target.type == "Nart" and event.other.type == "food" then event.other:removeSelf() ---skor ekleme yeri--- score = score + 1 scoreText.text = "Score: " .. score else alert('lose') transition.cancel() timer.cancel(spawntimer) physics.pause() Runtime:removeEventListener("touch",moveNart) -- restartButtton= display.newImage ("resimler/restart.png") -- restartButtton.x = centerX -- restartButtton.y = display.contentCenterY+150 -- sceneGroup:insert (restartButtton) -- restartButtton:addEventListener("tap",gameOver) -- display.remove( restartButtton ) print("enes") composer.gotoScene("menu") -- timer.performWithDelay( 1000, gameOver) end end end ----------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---Skor guncelleme---- local function updateText() --livesText.text = "Lives: " .. lives scoreText.text = "Score: " .. score end ------------------------------------------------------------------------------ local function setupDisplay() local bg= display.newImage("resimler/arkaplan2.png") bg.width = screenWidth bg.height = screenHeight bg.x=centerX bg.y= centerY bg:addEventListener("touch", moveNart) scoreText = display.newText( "Score: " .. score, centerX, screenTop + 10, native.systemFont,20 ) scoreText:setTextColor( 0, 0 ,204 ) audio.play(muzik, {loops = -1, channel = 1}) --Oyuncu ekleme--- Nart = display.newImage("resimler/nanu.png") Nart.x=centerX Nart.y=screenBottom-60 Nart.type="Nart" Nart.collision = NartCollision-- Nart:addEventListener("collision", Nart)-- -- physics.addBody(Nart) -- physics.addBody( Nart, "static", {density=1, friction=5, radius=25})-- --yer ekleme --- local ground =display.newImage("resimler/ground.png") ground.x=centerX ground.y=screenBottom-8 if pileUp then physics.addBody( ground, "static" ) end cim = display.newImageRect("resimler/grass.png", 320, 30) cim.x=centerX cim.y=screenBottom-15 end setupDisplay() spawntimer = timer.performWithDelay(500, spawnObject, 0 ) --------------------gameover --------------------------- local function gameover () composer.gotoScene ("menu") end ---------------------------------------------- -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = scene.view -- Code here runs when the scene is first created but has not yet appeared on screen end -- show() function scene:show( event ) local sceneGroup = scene.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 -- hide() function scene:hide( event ) local sceneGroup = scene.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 local prevScene = composer.getSceneName( "previous" ) if(prevScene) then composer.removeScene(prevScene) end end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view setupDisplay () spawnObject () updateText() end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
  1.  That code post is too big.  You’d be better off zipping the entire project up and posing a link to it from drop box or another sharing service.

  2. Did you read the docs or leap right into using Composer?  

If you have not yet read the guide, you should.  It explains a lot:

And then be sure you know where the composer API docs are:

  1. Finally, there is a sample that comes with Corona in

‘~\Corona Labs\Corona SDK\Sample Code\Interface\Composer’

As well, I have a ton of samples doing various things with Composer here:

  1. You should package your game code in a module and call that module from the composer scene.  That way you can do all of your design and testing work separately.

Once you get start, restart, stop, etc working, then just use them in a composer scene.

I tell all new folks the same thing, DO NOT code a game directly in a composer scene, because it simply adds another layer of things you need to understand on top of the ‘core game programming’.  

  1.  That code post is too big.  You’d be better off zipping the entire project up and posing a link to it from drop box or another sharing service.

  2. Did you read the docs or leap right into using Composer?  

If you have not yet read the guide, you should.  It explains a lot:

And then be sure you know where the composer API docs are:

  1. Finally, there is a sample that comes with Corona in

‘~\Corona Labs\Corona SDK\Sample Code\Interface\Composer’

As well, I have a ton of samples doing various things with Composer here:

  1. You should package your game code in a module and call that module from the composer scene.  That way you can do all of your design and testing work separately.

Once you get start, restart, stop, etc working, then just use them in a composer scene.

I tell all new folks the same thing, DO NOT code a game directly in a composer scene, because it simply adds another layer of things you need to understand on top of the ‘core game programming’.