电晕中的重新加载屏幕

发布于 2024-12-13 04:41:06 字数 66 浏览 1 评论 0原文

我正在电晕中开发一个应用程序,我需要一次又一次地重新加载同一屏幕。我不知道如何做到这一点,有人可以用代码向我解释一下吗

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

不语却知心 2024-12-20 04:41:06

1) 导演类

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

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
书间行客 2024-12-20 04:41:06

Storyboard API 自构建 2011.678 起可用

这是使用构建 2011.704 的 Storyboard API 的示例,

每次触摸都会重新加载整个场景

--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

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
总攻大人 2024-12-20 04:41:06

我不太清楚,但我的游戏我使用相同的 lua 文件来更改场景。

myscene.lua

导演:changeScene(“我的场景”)

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

myscene.lua

director:changeScene("myscene")

小嗷兮 2024-12-20 04:41:06

我尝试了另一种对我有用的方法,示例如下 -

步骤 1 - 创建一个对象,例如 - 本地 reloadScene

步骤 2 - 当需要重新加载场景时应用步骤 2 -
重新加载场景=“是”
storyboard.reloadScene("eventsButtonClicked")

步骤3-应用步骤3,当不需要重新加载场景时-
函数场景2a:退出场景(事件)
如果 reloadScene == "YES" 那么
Storyboard.purgeScene("eventsButtonClicked")
重新加载场景=“否”
结尾
结尾
scene2a:addEventListener( "exitScene", scene2a )

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 )

夜光 2024-12-20 04:41:06

我认为你应该遵循以下步骤:我已经实现了在 Corona 中重新加载/重新启动情节提要场景的步骤。

第 1 步:创建一个函数或代码行,以便从要重新加载或重新启动的故事板类中一次又一次地重新启动/重新加载同一场景。

function forRestart(event)

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

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

return true;
end

第 2 步:创建一个 lua 文件:命名为重新加载。下面是 reload.lua 文件的模板。

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

-- 场景移到屏幕上后立即调用:

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

-- 当场景即将移出屏幕时调用:

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

-- 如果场景的视图被移除,则 scene:destroyScene() 将被调用之前调用:

 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

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
赠佳期 2024-12-20 04:41:06

您还可以使用此方法重新加载同一屏幕:
timer.performWithDelay(500, function()director:changeScene("你的场景名称"));
但在调用上述函数之前,您需要从显示组中删除所有对象。

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.

↘人皮目录ツ 2024-12-20 04:41:06

您可以创建一个重新加载场景,
并调用它来 Roload Any Scene 。
像这样

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

你的重新加载场景代码就像

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

    composer.removeScene( reloadSceneName )
    composer.gotoScene( reloadSceneName , reloadSceneOptions )
end 

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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文