如何在 Corona SDK 中重新启动场景?

发布于 2024-12-22 20:49:37 字数 734 浏览 2 评论 0原文

我正在使用 Corona 的 SDK storyboard API,在我的应用程序中我想让用户“再试一次”的水平。我虽然简单地调用

storyboard.gotoScene("level20","flip") 

level20 是当前场景,但在事件发生后(点击“重试”按钮)就可以了,但场景将所有显示对象保留在同一位置,而不是像我来自不同场景时那样重置。

是否可以从同一场景重新启动场景?

谢谢。

编辑:

我使用Corona的版本:2.0.0,内部版本:2011.704

编辑(可能的修复):

我可能已经找到了修复。来自“场景清除和删除”中的文档:当您转到新场景时,前一个场景会保留在内存中以便快速重新加载,scene:createScene() 会删除此内存。

因此,我发现的修复方法是调用 scene:createScene(),它似乎有效,但如果这是错误的方法,请告诉我们。谢谢。

Am using Corona's SDK storyboard API, in my app I want to let users "try again" the level. I though simply calling

storyboard.gotoScene("level20","flip") 

where level20 is the current scene, after an event (taping the "try again" button) would work but the scene keeps all it's display objects in the same place instead of resetting like when I come from a different scene.

Is it possible to restart a scene from the same scene?

Thanks.

Edit:

Am using Corona's Version: 2.0.0, Build: 2011.704

Edit (possible fix):

I might have found the fix. From the docs in the "Scene Purging and Removal": when you go to a new scene the previous scene sticks around in memory for fast reloading, scene:createScene() removes this memory.

So the fix I found was to call scene:createScene(), it seems to work but if this is the wrong approach please let us know. Thanks.

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

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

发布评论

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

评论(3

风为裳 2024-12-29 20:49:37

创建一个“虚拟场景”,您可以在createScene()下使用storyboard.purgeScene(“level20”),然后在enterScene()中创建一个函数,您可以使用storyboard.gotoScene(“level20”,“flip”)。确保你的storyboard.purgeScene('虚拟场景')在''关卡'' 20。你的下一个问题将是“我需要创建20个虚拟场景吗?”不要将变量存储在storyboard.level = '20'下,而不是从'虚拟场景'中调用它

create a 'dummy scene' where u can storyboard.purgeScene("level20") under createScene() then create a function in enterScene() that u can storyboard.gotoScene("level20","flip"). make sure u storyboard.purgeScene ('dummy scene') in ''level'' 20. Your next question will be 'Do I need to create 20 dummy scenes?' No store a variable under storyboard.level = '20' than call it from the 'dummy scene'

紫竹語嫣☆ 2024-12-29 20:49:37

上面似乎效果不好,我用简单的过渡效果得到了我的解决方案。

function scene:refresh(event)
    local v = self.view
         transition.to(v, {time=500, alpha=0.5, transition=easing.inExpo, onComplete=function(e)
        self:destroyScene()
        self:createScene()
        storyboard.reloadScene()
        transition.to(v, {time=500, alpha=1, transition=easing.outExpo})
    end})
end

Above seemed not work well, I got my solution with simple transition effect.

function scene:refresh(event)
    local v = self.view
         transition.to(v, {time=500, alpha=0.5, transition=easing.inExpo, onComplete=function(e)
        self:destroyScene()
        self:createScene()
        storyboard.reloadScene()
        transition.to(v, {time=500, alpha=1, transition=easing.outExpo})
    end})
end
过期以后 2024-12-29 20:49:37

我自己实际上并没有这样做,但基于这里的讨论:

http://blog.anscamobile.com/2011/11/introducing-the-storyboard-api/

看来您需要致电storyboard.purgeScene("level20") 在调用 storyboard.gotoScene("level20","flip") 之前

I haven't actually done this myself, but based on the discussion here:

http://blog.anscamobile.com/2011/11/introducing-the-storyboard-api/

It looks like you'll need to call storyboard.purgeScene("level20") before calling storyboard.gotoScene("level20","flip")

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