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]