removeScene or purgeScene doesnt work. Help!

I wana make like this “level1” > “gameoverScene” > “level1”

I try using removeScene or purgeScene but “level1” not reload normally, the image still stuck there. help!

here my code “level1”

[lua]



– level1.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

– include Corona’s “physics” library
local physics = require (“physics”)
local tendangan = false
physics.start()

local widget = require “widget”

– forward declarations and other locals
_W = display.contentWidth*0.5;
_H = display.contentHeight;
local motionx = 0
local speed = 5
local score = 1
local life = {}

local camera={}
local timeLimit = 50
local life =3
local objectSheet = require (“pitung”)
local prajuritSheet = require (“tentara”)

local perspective = require(“perspective”)
local camera = perspective.createView()


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
–   unless storyboard.removeScene() is called.


– Called when the scene’s view does not exist:

 – create a grey rectangle as the backdrop
 
 
 – make a crate (off-screen), position it, and rotate slightly
function scene:createScene( event )
 storyboard.removeAll()
 local group = self.view

–bacground
display.setDefault(“background”, 135,206, 250)

 
–gunung------------------------------------------------------------------------------------------
local gunung=display.newImageRect(“images/gunung.png”,464, 265)
gunung.x = display.contentCenterX
gunung.y = display.contentCenterY

local gunung2=display.newImageRect(“images/gunung.png”,464, 265)
gunung2.x = gunung.width+display.contentCenterX
gunung2.y = display.contentCenterY

local gunung3=display.newImageRect(“images/gunung.png”,464, 265)
gunung3.x = gunung.width*2+display.contentCenterX
gunung3.y = display.contentCenterY

local gunung4=display.newImageRect(“images/gunung.png”,464, 265)
gunung4.x = gunung.width*3+display.contentCenterX
gunung4.y = display.contentCenterY

local gunung5=display.newImageRect(“images/gunung.png”,464, 265)
gunung5.x = gunung.width*4+display.contentCenterX
gunung5.y = display.contentCenterY

local gunung6=display.newImageRect(“images/gunung.png”,464, 265)
gunung6.x = gunung.width*5+display.contentCenterX
gunung6.y = display.contentCenterY

local gunung7=display.newImageRect(“images/gunung.png”,464, 265)
gunung7.x = gunung.width*6+display.contentCenterX
gunung7.y = display.contentCenterY

local gunung8=display.newImageRect(“images/gunung.png”,464, 265)
gunung8.x = gunung.width*7+display.contentCenterX
gunung8.y = display.contentCenterY

local gunung9=display.newImageRect(“images/gunung.png”,464, 265)
gunung9.x = gunung.width*8+display.contentCenterX
gunung9.y = display.contentCenterY

local gunung10=display.newImageRect(“images/gunung.png”,464, 265)
gunung10.x = gunung.width*9+display.contentCenterX
gunung10.y = display.contentCenterY
local gunung11=display.newImageRect(“images/gunung.png”,464, 265)
gunung11.x = gunung.width*10+display.contentCenterX
gunung11.y = display.contentCenterY
local gunung12=display.newImageRect(“images/gunung.png”,464, 265)
gunung12.x = gunung.width*11+display.contentCenterX
gunung12.y = display.contentCenterY
local gunung13=display.newImageRect(“images/gunung.png”,464, 265)
gunung13.x = gunung.width*12+display.contentCenterX
gunung13.y = display.contentCenterY

local gunung14=display.newImageRect(“images/gunung.png”,464, 265)
gunung14.x = gunung.width*13+display.contentCenterX
gunung14.y = display.contentCenterY

—awan-----------------------------------------------------------------------

local awan=display.newImageRect(“images/awan.png”,1300, 324)
awan.x = display.contentCenterX
awan.y = display.contentCenterY

local awan2=display.newImageRect(“images/awan.png”,1300, 324)
awan2.x = awan.width+display.contentCenterX
awan2.y = display.contentCenterY

local awan3=display.newImageRect(“images/awan.png”,1300, 324)
awan3.x = awan.width*2+display.contentCenterX
awan3.y = display.contentCenterY

local awan4=display.newImageRect(“images/awan.png”,1300, 324)
awan4.x = awan.width*3+display.contentCenterX
awan4.y = display.contentCenterY

local awan5=display.newImageRect(“images/awan.png”,1300, 324)
awan5.x = awan.width*4+display.contentCenterX
awan5.y = display.contentCenterY

local awan6=display.newImageRect(“images/awan.png”,1300, 324)
awan6.x = awan.width*5+display.contentCenterX
awan6.y = display.contentCenterY

local awan7=display.newImageRect(“images/awan.png”,1300, 324)
awan7.x = awan.width*6+display.contentCenterX
awan7.y = display.contentCenterY

local awan8=display.newImageRect(“images/awan.png”,1300, 324)
awan8.x = awan.width*7+display.contentCenterX
awan8.y = display.contentCenterY

— rumah--------------------------------------------------------------------------------
local rumah=display.newImageRect(“images/rumah.png”,412, 333)
rumah.x = display.contentCenterX
rumah.y = display.contentCenterY

local rumah2=display.newImageRect(“images/rumah.png”,412, 333)
rumah2.x = gunung.width*4+display.contentCenterX
rumah2.y = display.contentCenterY

local rumah3=display.newImageRect(“images/rumah.png”,412, 333)
rumah3.x = gunung.width*5+display.contentCenterX
rumah3.y = display.contentCenterY

–atap rumah atap---------------------------------------------------------------------------------------

local atap=display.newImageRect(“images/atap.png”,412, 5)
atap.x = display.contentCenterX
atap.y = display.contentCenterY
physics.addBody( atap, “static”, { friction=0.3, shape=atapShape } )

local atap2=display.newImageRect(“images/atap.png”,412, 5)
atap2.x = gunung.width*4+display.contentCenterX
atap2.y = display.contentCenterY
physics.addBody( atap2, “static”, { friction=0.3, shape=atap2Shape } )

local atap3=display.newImageRect(“images/atap.png”,412, 5)
atap3.x = gunung.width*5+display.contentCenterX
atap3.y = display.contentCenterY
physics.addBody( atap3, “static”, { friction=0.3, shape=atap3Shape } )
–pitung------------------------------------------------------------------------------------------

local cobaSheet = graphics.newImageSheet (“pitung.png”, objectSheet:getSheet())
local coba = display.newSprite (cobaSheet, objectSheet:getSequenceData())
coba:setSequence(“idle”,“kiri”,“kanan”)
coba.x=200
coba.y=0
coba:play()

physics.addBody( coba,“dynamic”, {  friction=0.5, bounce=0} )
coba.isFixedRotation=true
group:insert(coba)

–tentara------------------------------------------------------------------------------------------

local tentaraSheet = graphics.newImageSheet (“tentara.png”, prajuritSheet:getSheet())
local tentara = display.newSprite (tentaraSheet, prajuritSheet:getSequenceData())
tentara:setSequence(“nembak”)
tentara.x, tentara.y = gunung.width*3+display.contentCenterX,0
tentara:play()
physics.addBody( tentara,“dynamic”, {  friction=0.5, bounce=0.3 } )

local tentaraSheet = graphics.newImageSheet (“tentara.png”, prajuritSheet:getSheet())
local tentara2= display.newSprite (tentaraSheet, prajuritSheet:getSequenceData())
tentara2:setSequence(“nembak”)
tentara2.x, tentara2.y = gunung.width*4+display.contentCenterX+300,0
tentara2:play()
physics.addBody( tentara2,“dynamic”, {  friction=0.5, bounce=0.3 } )

local tentaraSheet = graphics.newImageSheet (“tentara.png”, prajuritSheet:getSheet())
local tentara3= display.newSprite (tentaraSheet, prajuritSheet:getSequenceData())
tentara3:setSequence(“nembak”)
tentara3.x, tentara3.y = gunung.width*8+display.contentCenterX+300,0
tentara3:play()
physics.addBody( tentara3,“dynamic”, {  friction=0.5, bounce=0.3 } )

–papan warning-----------------------------------------------------------------------------------

local warning = display.newImageRect(“images/warning1.png”, 70, 100)
warning.x= gunung.width*2+display.contentCenterX
warning.y = display.contentCenterY + 80

local warning2 = display.newImageRect(“images/warning1.png”, 70, 100)
warning2.x= gunung.width*7+display.contentCenterX
warning2.y = display.contentCenterY + 80

–nyawa--------------------------------------------------------------------------------------------
local nyawa1 = widget.newButton
{
 default=“images/nyawa.png”,
 width=30,
 height=38
}
nyawa1.x = 30
nyawa1.y = 40

local nyawa2 = widget.newButton
{
 default=“images/nyawa.png”,
 width=30,
 height=38
}
nyawa2.x = 60
nyawa2.y = 40

local nyawa3 = widget.newButton
{
 default=“images/nyawa.png”,
 width=30,
 height=38
}
nyawa3.x = 90
nyawa3.y = 40

–bawah
 local grass = display.newImageRect( “images/bawah.png”, _W*22, 82)
 grass:setReferencePoint( display.BottomLeftReferencePoint )
 grass.x, grass.y = 0, display.contentHeight+50
 
 physics.addBody( grass, “static”, { friction=0.3, shape=grassShape } )
 

 local left = widget.newButton{
 default=“images/kiri.png”,
 over = “images/kiriPencet.png”,
 width = 60,
 height= 40,

}
 left.x=45
 left.y=280

 local right = widget.newButton{
 default=“images/kanan.png”,
 over=“images/kananPencet.png”,
 width=60,
 height=40
}
 right.x = 150
 right.y = 280

 local lompat = widget.newButton{

 default=“images/atas.png”,
 over = “images/atasPencet.png”,
 width = 50,
 height= 50
}

 lompat.x = 460
 lompat.y = 280

local serang = widget.newButton{

 default=“images/serang.png”,
 over = “images/serangPencet.png”,
 width = 50,
 height= 50
}
serang.x = 390
serang.y =280
serang.id = gebuk

–suara------------------------------------------------------------------------------------

–kiri
 function  left:touch( )
 motionx = -speed
 coba:setSequence(“kiri”)
 coba:play()
 

 
end

left:addEventListener(“touch”,left)

– kanan
 function right:touch( )
  
  motionx = speed
  coba:setSequence(“kanan”)
  coba:play()
  
  

 end
 right:addEventListener(“touch”, right)
 
 
 --lompat

 function lompat:touch( event )
  if (event.phase == “began” and terbang == false) then
   terbang = true
   coba :setLinearVelocity (0, -300)
   coba:setSequence(“lompat”)
   coba:play()

  end
 end
 lompat:addEventListener(“touch”, lompat)

function serang:touch( )
 
  
  motionx = speed
  coba:setSequence(“tendang”)
  coba:play()
  updateScore()
  

end
 serang:addEventListener(“touch”, serang)
 

 local  function movecreate( event )

  coba.x = coba.x + motionx

 end
 Runtime:addEventListener(“enterFrame”, movecreate)
 local function stop( event )
 if event.phase == “ended” then
 motionx = 0
 coba:setSequence(“idle”)
 coba:play()
 
end

 --nyawa

end
Runtime:addEventListener(“touch”, stop)

-----limit lompat-------------------------

----------darah berkurang----------------------------------

function kurangdarah(event )
 if life==3 then

  coba.isVisibile= true
  life = life-1
  nyawa3:removeSelf()
  
  elseif life==2 then
   coba.isVisibile= true
   life = life-1
   nyawa2:removeSelf()
   elseif life==1 then
    coba.isVisibile= true
    life = life -1
    nyawa1:removeSelf()
    gameOver()

   else
    if life== 3 then
    
    
   
    
  

   
 – body
end
end
end

—oncomplete--------------------
local function listener(obj)
 tentara:removeSelf()
 
end
local function listener2(obj)
 tentara2:removeSelf()
 
end
local function listener3(obj)

 tentara3:removeSelf()
end

—gameover---------
 function gameOver()
 storyboard.removeAll()
 Runtime:removeEventListener(“touch”,left)
 Runtime:removeEventListener(“touch”, right)
 Runtime:removeEventListener(“touch”, lompat)
 Runtime:removeEventListener(“touch”, serang)
  Runtime:removeEventListener(“enterFrame”, movecreate)
  Runtime:removeEventListener(“collision”,coba)
 storyboard.gotoScene(“gameoverScene”, “fade”, 1000)
 

 
end
-----update score-----------------------------------------------------------------------
local function updateScore()
 score= score + 1;
 scoreAngka.text = score

 
end
local playerScore = display.newText(“Score:”, display.contentWidth/2+150,0, native.systemFont, 30)
playerScore:setTextColor(0,0,0)
local scoreAngka = display.newText(score,display.contentWidth/2+160,0,native.systemFont,50)
scoreAngka:setTextColor(0,0,0)

—collision------------------------------

function cobaCollision( self, event )
 if event.phase == “began” then
  

  if event.target.type == “coba” and event.other.type ==“tentara” then
   kurangdarah()
   transition.to(tentara, {time=1000,alpha=0,onComplete=listener})
  
   updateScore()
  

   elseif event.target.type == “coba” and event.other.type ==“tentara2” then
   kurangdarah()
    transition.to(tentara2, {time=1000,alpha=0,onComplete=listener2})
    

   elseif event.target.type == “coba” and event.other.type ==“tentara3” then
   kurangdarah()
    transition.to(tentara3, {time=1000,alpha=0,onComplete=listener3})

  print (“aw”)
 else
  if event.target.type ==“coba” and event.other.type ==“grass” then
   terbang=false
   
   
   elseif event.target.type==“coba” and event.other.type ==“atap” then
    terbang=false
  
   
  print (“hmm”)
end
end
end
end

coba.collision=cobaCollision
coba.type = “coba”
coba:addEventListener(“collision”,coba)

tentara.type=“tentara”
tentara2.type=“tentara2”
tentara3.type=“tentara3”
grass.type=“grass”

atap.type=“atap”
atap2.type=“atap”
atap3.type=“atap”
serang.type=“serang”

local timeLeft = display.newText(timeLimit, display.contentWidth/2, 0, native.systemFont, 50)
 timeLeft:setTextColor(0, 0, 0)
 
 local function  timerDown( )
  timeLimit = timeLimit-1
  timeLeft.text = timeLimit
  if (timeLimit==0) then
   print (“time out”)
   
  gameOver()
  
 end
end
 --local loop = detik1.text…detik2.text
 --print(loop)
 timer.performWithDelay (1000,timerDown,timeLimit)


camera:add(coba,1,true)
camera:add(nyawa1,1,false)
camera:add(tentara,1,false)
camera:add(tentara2,1,false)
camera:add(tentara3,1,false)

camera:add(grass,2,false)

camera:add(warning,3,false)
camera:add(warning2,3,false)
camera:add(rumah,3,false)
camera:add(rumah2,3,false)
camera:add(rumah3,3,false)

camera:add(gunung,4,false)
camera:add(gunung2,4,false)
camera:add(gunung3,4,false)
camera:add(gunung4,4,false)
camera:add(gunung5,4,false)
camera:add(gunung6,4,false)
camera:add(gunung7,4,false)
camera:add(gunung8,4,false)
camera:add(gunung9,4,false)
camera:add(gunung10,4,false)
camera:add(gunung11,4,false)
camera:add(gunung12,4,false)
camera:add(gunung13,4,false)

camera:add(awan,5,false)
camera:add(awan2,5,false)
camera:add(awan3,5,false)
camera:add(awan4,5,false)
camera:add(awan5,5,false)
camera:add(awan6,5,false)
camera:add(awan7,5,false)
camera:add(awan8,5,false)

camera:add(atap,6,false)
camera:add(atap2,6,false)
camera:add(atap3,6,false)

local levelWidth = camera:layer(2).width
camera:setBounds(display.contentWidth/2,levelWidth-display.contentWidth, -1000,display.contentHeight)
camera.damping=3

group:insert(camera)
group:insert(nyawa1)
group:insert(nyawa2)
group:insert(nyawa3)
group:insert(timeLeft)
group:insert(playerScore)
group:insert(scoreAngka)

group:insert(left)
group:insert(right)
group:insert(lompat)
group:insert(serang)

end

function scene:enterScene( event )
  
 local group = self.view

 camera:track()
 
 physics.start()
 end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
 local group = self.view
 Runtime:removeEventListener(“touch”,left)
 Runtime:removeEventListener(“touch”, right)
 Runtime:removeEventListener(“touch”, lompat)
 Runtime:removeEventListener(“touch”, serang)
  Runtime:removeEventListener(“enterFrame”, movecreate)
  Runtime:removeEventListener(“collision”,coba)
  
 storyboard.removeAll()

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
 local group = self.view
 
 
 package.loaded[physics] = nil
 physics = nil
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene

[/lua]

First,  storyboard.* is no longer supported.  So, you should start using composer if you want to be up-to-date and also be able to get and find help.

Second,  I’ve written a ton of examples (for composer) here, including one that remakes a scene: 

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Oh, and if you can tell me, where did you get your code to start?  I’ve noticed a lot of new folks still using storyboard which is weird since it has been unsupported for some time.  I’d like to help clean up these storyboard examples in some way, but I don’t know where folks are getting them.

Thanks,

Ed

PS - A trick I use for remaking all content in a scene is as follows:

  1. Do not create content in scene:create(),  create content during the ‘will’ phase while entering the scene.

  2. Have a file level variable called parentGroup (or something like that).  Simply declare it toward the top of the file.

    local parentGroup

  3. When you create your content( during “will” phase of enter scene method), create a new display Group and save it in ‘parentGroup’, then insert that group into the sceneGroup, finally add all new content into parentGroup.  This will make all content children of parentGroup and grandchildren of sceneGroup.

    parentGroup = display.newGroup() sceneGroup:insert( parentGroup) – Now create all content in parentGroup local circ = display.newCircle( parentGroup, 100, 100, 10 )

  4. When you exit the scene, destroy ‘parentGroup’ during the ‘did’ phase. 

    display.remove( parentGroup ) – Destroys all objects that were inserted into this group parentGroup = nil

Similarly, start all listeners when creating objects, and stop them all after/before destroying parentGroup.

Easy-peasy.

Hi @kali8pm. Thanks for your question and thanks for using code formatting to show us your code. However, it’s still really hard to read. I would like to direct you to this tutorial: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

When you post well formatted code then your code will be much easier to read and you will get better results from the community.

Next, Corona SDK is pretty flexible and you will find there are usually multiple ways to do things. @roaminggamer has found success using Composer the way he described. Personally and officially speaking, all of our documentation, tutorials, sample apps ask you to create your objects in scene:create(). This is our recommended best practice.

I agree with @roaminggamer, I would love to know where you’re getting Storyboard based starter code.

To your question though, what images are getting stuck on the screen? Are  your level1 images getting stuck on your gameover scene? Or are you gameover scene images hanging around when you go back? Or are you getting duplicate level1 images?

Rob

@roaminggamer : thanks for your explaintation, u make me think positively about this forum :slight_smile:

but i cant switch to composer now, this for my exam tomorow, but im still confused :frowning:

@Rob : glad you reply my post, this my 2nd post and got reply for the first time :slight_smile:

pls help me sir…

here my code “gameoverScene”

[lua]



– menu.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

– include Corona’s “widget” library
local widget = require “widget”


– forward declarations and other locals
local playBtn

– ‘onRelease’ event listener for playBtn


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
–   unless storyboard.removeScene() is called.


– Called when the scene’s view does not exist:
function scene:createScene( event )
 
 local group = self.view

 – display a background image
 display.setDefault(“background”, 0,0, 0)
 
 – create/position logo/title image on upper-half of the screen

 
 —pitung sprite
 local objectSheet = require (“gameover”)
 local gameoverSheet = graphics.newImageSheet (“images/gameover.png”, objectSheet:getSheet())
 local gameover = display.newSprite (gameoverSheet, objectSheet:getSequenceData())
 gameover:setSequence()
 gameover.x, gameover.y = 240,135
 gameover:play()

 – create a widget button (which will loads level1.lua on release)

 local function onPlayBtnReleaseMenu(event)
 
 – go to level1.lua scene
 storyboard.purgeOnSceneChange = true

 storyboard.gotoScene( “menu”, “fade”, 500 )
 
 —return true – indicates successful touch
end

 local function onPlayBtnReleaseRestart()
 
 – go to level1.lua scene
 
 storyboard.gotoScene ( “level1”, “fade”, 500 )
 
 —return true – indicates successful touch
end
 
 menu = widget.newButton{
  
  default=“images/menu1.png”,
  over=“images/menu2.png”,
  width=70, height=50,
  onRelease = onPlayBtnReleaseMenu – event listener function
 }
 menu:setReferencePoint( display.CenterReferencePoint )
 menu.x = 40
 menu.y = 290

 restart = widget.newButton{
  
  default=“images/restart1.png”,
  over=“images/restart2.png”,
  width=70, height=50,
  onRelease = onPlayBtnReleaseRestart – event listener function
 }
 restart:setReferencePoint( display.CenterReferencePoint )
 restart.x = 430
 restart.y = 290

 – all display objects must be inserted into group
 
 group:insert (gameover)
 group:insert (menu)
 group:insert (restart)
 
 
end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )

 local group = self.view
 
 – INSERT code here (e.g. start timers, load audio, start listeners, etc.)
 
end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
 local group = self.view
 
 – INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
 
end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
 local group = self.view
 
 if playBtn then
  playBtn:removeSelf() – widgets must be manually removed
  playBtn = nil
 end
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene

[/lua]

sry for another bad format…

I was confused a lot for 2 weeks :frowning:

First,  storyboard.* is no longer supported.  So, you should start using composer if you want to be up-to-date and also be able to get and find help.

Second,  I’ve written a ton of examples (for composer) here, including one that remakes a scene: 

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Oh, and if you can tell me, where did you get your code to start?  I’ve noticed a lot of new folks still using storyboard which is weird since it has been unsupported for some time.  I’d like to help clean up these storyboard examples in some way, but I don’t know where folks are getting them.

Thanks,

Ed

PS - A trick I use for remaking all content in a scene is as follows:

  1. Do not create content in scene:create(),  create content during the ‘will’ phase while entering the scene.

  2. Have a file level variable called parentGroup (or something like that).  Simply declare it toward the top of the file.

    local parentGroup

  3. When you create your content( during “will” phase of enter scene method), create a new display Group and save it in ‘parentGroup’, then insert that group into the sceneGroup, finally add all new content into parentGroup.  This will make all content children of parentGroup and grandchildren of sceneGroup.

    parentGroup = display.newGroup() sceneGroup:insert( parentGroup) – Now create all content in parentGroup local circ = display.newCircle( parentGroup, 100, 100, 10 )

  4. When you exit the scene, destroy ‘parentGroup’ during the ‘did’ phase. 

    display.remove( parentGroup ) – Destroys all objects that were inserted into this group parentGroup = nil

Similarly, start all listeners when creating objects, and stop them all after/before destroying parentGroup.

Easy-peasy.

Hi @kali8pm. Thanks for your question and thanks for using code formatting to show us your code. However, it’s still really hard to read. I would like to direct you to this tutorial: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

When you post well formatted code then your code will be much easier to read and you will get better results from the community.

Next, Corona SDK is pretty flexible and you will find there are usually multiple ways to do things. @roaminggamer has found success using Composer the way he described. Personally and officially speaking, all of our documentation, tutorials, sample apps ask you to create your objects in scene:create(). This is our recommended best practice.

I agree with @roaminggamer, I would love to know where you’re getting Storyboard based starter code.

To your question though, what images are getting stuck on the screen? Are  your level1 images getting stuck on your gameover scene? Or are you gameover scene images hanging around when you go back? Or are you getting duplicate level1 images?

Rob

@roaminggamer : thanks for your explaintation, u make me think positively about this forum :slight_smile:

but i cant switch to composer now, this for my exam tomorow, but im still confused :frowning:

@Rob : glad you reply my post, this my 2nd post and got reply for the first time :slight_smile:

pls help me sir…

here my code “gameoverScene”

[lua]



– menu.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

– include Corona’s “widget” library
local widget = require “widget”


– forward declarations and other locals
local playBtn

– ‘onRelease’ event listener for playBtn


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
–   unless storyboard.removeScene() is called.


– Called when the scene’s view does not exist:
function scene:createScene( event )
 
 local group = self.view

 – display a background image
 display.setDefault(“background”, 0,0, 0)
 
 – create/position logo/title image on upper-half of the screen

 
 —pitung sprite
 local objectSheet = require (“gameover”)
 local gameoverSheet = graphics.newImageSheet (“images/gameover.png”, objectSheet:getSheet())
 local gameover = display.newSprite (gameoverSheet, objectSheet:getSequenceData())
 gameover:setSequence()
 gameover.x, gameover.y = 240,135
 gameover:play()

 – create a widget button (which will loads level1.lua on release)

 local function onPlayBtnReleaseMenu(event)
 
 – go to level1.lua scene
 storyboard.purgeOnSceneChange = true

 storyboard.gotoScene( “menu”, “fade”, 500 )
 
 —return true – indicates successful touch
end

 local function onPlayBtnReleaseRestart()
 
 – go to level1.lua scene
 
 storyboard.gotoScene ( “level1”, “fade”, 500 )
 
 —return true – indicates successful touch
end
 
 menu = widget.newButton{
  
  default=“images/menu1.png”,
  over=“images/menu2.png”,
  width=70, height=50,
  onRelease = onPlayBtnReleaseMenu – event listener function
 }
 menu:setReferencePoint( display.CenterReferencePoint )
 menu.x = 40
 menu.y = 290

 restart = widget.newButton{
  
  default=“images/restart1.png”,
  over=“images/restart2.png”,
  width=70, height=50,
  onRelease = onPlayBtnReleaseRestart – event listener function
 }
 restart:setReferencePoint( display.CenterReferencePoint )
 restart.x = 430
 restart.y = 290

 – all display objects must be inserted into group
 
 group:insert (gameover)
 group:insert (menu)
 group:insert (restart)
 
 
end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )

 local group = self.view
 
 – INSERT code here (e.g. start timers, load audio, start listeners, etc.)
 
end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
 local group = self.view
 
 – INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
 
end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
 local group = self.view
 
 if playBtn then
  playBtn:removeSelf() – widgets must be manually removed
  playBtn = nil
 end
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene

[/lua]

sry for another bad format…

I was confused a lot for 2 weeks :frowning: