Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reloading screen in corona

Tags:

lua

coronasdk

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

like image 928
Vivek Kalkur Avatar asked Nov 01 '11 05:11

Vivek Kalkur


3 Answers

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
like image 112
k2fx Avatar answered Oct 10 '22 12:10

k2fx


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
like image 41
cctan Avatar answered Oct 10 '22 13:10

cctan


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

myscene.lua

director:changeScene("myscene")

like image 30
Malarkodi Avatar answered Oct 10 '22 12:10

Malarkodi