I am developing an application in corona where I need to reload the same screen again and again.I don't have any idea as how to do it,Can anybody explain me this with a code
1) director class
2) main.lua
display.setStatusBar (display.HiddenStatusBar)
--> Hides the status bar
local director = require ("director")
--> Imports director
local mainGroup = display.newGroup()
--> Creates a main group
local function main()
--> Adds main function
mainGroup:insert(director.directorView)
--> Adds the group from director
director:changeScene("myscene")
--> Change the scene, no effects
return true
end
main()
3) myscene.lua
module(..., package.seeall)
function new()
local localGroup = display.newGroup()
local redbutton = display.newImage ("redbutton.png")
redbutton.x = 160
redbutton.y = 100
localGroup:insert(redbutton)
local function pressRed (event)
if event.phase == "ended" then
director:changeScene ("reloader")
end
end
redbutton:addEventListener ("touch", pressRed)
return localGroup
end
4) reloader.lua
module(..., package.seeall)
function new()
local localGroup = display.newGroup()
local function listener( event )
director:changeScene ("myscene", "fade")
end
timer.performWithDelay(50, listener )
return localGroup
end
Storyboard API is available since build 2011.678
Here's a sample using the storyboard API using build 2011.704
each touch will reload the whole scene
--main.lua
module(...,package.seeall)
local storyboard=require("storyboard")
local scene=storyboard.newScene()
scene.name="scnMenu"
function scene:createScene(event)
local group=self.view
bg=display.newRect(0,0,100,100)
group:insert(bg)
end
function scene:enterScene(event)
Runtime:addEventListener("touch",onTouch)
end
function onTouch(event)
storyboard.gotoScene("main","fade",1000)
end
function scene:exitScene(event)
Runtime:removeEventListener("touch",onTouch)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene",scene)
scene:addEventListener("enterScene",scene)
scene:addEventListener("exitScene",scene)
scene:addEventListener("destroyScene",scene)
return scene
I don't know exactly but my game i use same lua file for changeScene.
myscene.lua
director:changeScene("myscene")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With