Reloading screen in corona
Asked Answered
G

7

7

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

Greenway answered 1/11, 2011 at 5:22 Comment(0)
E
3

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
Exalt answered 2/11, 2011 at 8:31 Comment(0)
D
1

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
Domination answered 16/1, 2012 at 8:5 Comment(0)
B
1

I don't know exactly but my game i use same lua file for changeScene.

myscene.lua

director:changeScene("myscene")

Bloc answered 20/7, 2012 at 7:0 Comment(0)
A
0

I have tried another method which worked for me, example is given below -

Step 1- create a object like - local reloadScene

Step 2- Apply step 2, when reload scene is required - reloadScene = "YES" storyboard.reloadScene("eventsButtonClicked")

Step 3- Apply step3, when there is no need of reload scene - function scene2a:exitScene( event ) if reloadScene == "YES" then storyboard.purgeScene("eventsButtonClicked") reloadScene = "NO" end end scene2a:addEventListener( "exitScene", scene2a )

Ahimsa answered 4/4, 2013 at 10:0 Comment(0)
R
0

I think you should have to follow this steps: which i have implemented for reloading/restarting the storyboard scene in corona.

Step 1: Create an function or line of code to restart/reload same scene again and again from the storyboard class from where you want to reload or restart.

function forRestart(event)

if(event.phase == "ended") then

   local current_scene_name = storyboard.getCurrentSceneName()
   **storyboard.gotoScene( "reload", "fade", 250 )**

return true;
end

Step 2: Create an lua file with named reload. Below is the template for reload.lua file.

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

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

end

-- Called immediately after scene has moved onscreen:

function scene:enterScene( event )
    local group = self.view
    --purge level
    local previous_scene_name = storyboard.getPrevious()
    print("previous",previous_scene_name)
    --storyboard.removeScene(previous_scene_name)
    storyboard.purgeScene( previous_scene_name )
    --go back to level, by loading it from scratch
    storyboard.gotoScene( previous_scene_name, "fade", 250 )
end

-- Called when scene is about to move offscreen:

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

-- If scene's view is removed, scene:destroyScene() will be called just prior to:

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


-- "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
Rig answered 9/1, 2014 at 5:20 Comment(0)
T
0

You can also reload the same screen with this method: timer.performWithDelay(500, function()director:changeScene("your scene name")); But before calling the above function, you need to remove all the object from the display group.

Timetable answered 11/3, 2014 at 10:9 Comment(0)
V
0

You Can Create a Reload Scene , And Call that to Roload Any Scene . Like this

composer.gotoScene("Scene.Reload" , 
    {
        params = 
        {
            reloadSceneOptions = 
            {
                effect = "slideLeft",
                time = 500,
            },
            reloadSceneName = SceneName
        }
    })

And Your Reload Scene Code like

elseif phase == "did" then
    local reloadSceneOptions = event.params.reloadSceneOptions
    local reloadSceneName = event.params.reloadSceneName

    composer.removeScene( reloadSceneName )
    composer.gotoScene( reloadSceneName , reloadSceneOptions )
end 
Vocational answered 2/8, 2016 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.