Current status:
I have two files menu.lua and level1.lua . Menu file contains a button which go to scene level1.
The counter is created and once it completes the count an alert is visible. onclick of Play more buttons it goes back to the menu file.
On clicking again on this button, I want the scene to be reloaded. while it’s showing the last state.
I am confused after reading all reload and scene threads.
Thanks in Advance
Below is code:
–
– level1.lua
–
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “physics” library
local physics = require “physics”
physics.start(); physics.pause()
– forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
function levelfinished()
local loose=“you win”
local buttonLabels= {“Ok”,“Play more”}
local function onFinish( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
– Do nothing; dialog will simply dismiss
elseif 2 == i then
scene.view:removeSelf()
--storyboard.reloadScene(“level1”,“fade”,1500)
print(“play more”)
--timer.cancel(event.source)
--scene.view:removeSelf()
--storyboard.removeAll()
– storyboard.purgeScene(“level1”)
storyboard.gotoScene( “menu”, “fade”, 500 )
end
end
end
native.showAlert(loose, “Game finish”, buttonLabels, onFinish)
end
--countdown timer
counter= 0
– display text for timer
local gametimer =display.newText(counter,display.contentWidth-60,30)
gametimer.size = 16
local function countdown (event)
local timertext= display.newText(“Timer”,display.contentWidth-60,10)
local i = event.count
print (“i=”… i)
– print(“cratecount=”… fallingcrate.event.count)
gametimer.text= i
if i>= 6 then
local timestop = timer.cancel(event.source)
levelfinished()
end
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– create a grey rectangle as the backdrop
local background = display.newRect( 0, 0, screenW, screenH )
background:setFillColor( 128 )
– make a crate (off-screen), position it, and rotate slightly
local crate = display.newImageRect( “crate.png”, 90, 90 )
crate.x, crate.y = 160, -100
--crate.rotation = 15
– add physics to the crate
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )
– create a grass object and add physics (with custom shape)
local grass = display.newImageRect( “grass.png”, screenW, 82 )
grass:setReferencePoint( display.BottomLeftReferencePoint )
grass.x, grass.y = 0, display.contentHeight
– define a shape that’s slightly shorter than image bounds (set draw mode to “hybrid” or “debug” to see)
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, “static”, { friction=0.3, shape=grassShape } )
– all display objects must be inserted into group
group:insert( background )
group:insert( grass)
group:insert( crate )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
physics.start()
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print(“exit”)
physics.stop()
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
function scene:willEnterScene(evnt)
print(“rload”)
end
local counttimer=timer.performWithDelay(1000, countdown,60)
– 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 )
scene:addEventListener( “destroyScene”, scene )
scene:addEventListener(“willEnterScene”, scene)
return scene