如何过渡场景?

我正在制作一个游戏,使用storyboard技术。在进入场景时,我会从另一个模块调用显示对象lilEnem。我无法在场景更改时从内存中删除它,并且我不知道如何将它插入场景视图中,因为它是一个单独的文件。

点赞
用户1512564
用户1512564

首先,你需要使用Composer,因为Storyboard即将不再支持。有一个转换页面...它并不是很困难:

Storyboard到Composer的迁移

当你调用composer.gotoScene(或Storyboard)时,你可以向该场景传递参数:

(main.lua)

storyboard.gotoScene(“MyScene”,
  {
     params =
        {
           param1 =“something”,
           player = playerObj,等等。
        }
  }

然后,在被调用的场景中,在“show”方法中,你可以读取那些参数(这段代码使用composer):

(MyScene.lua)

local scene = composer.newScene()

function scene:show(event)
  if event.phase ==“did” then
     if event.params then
       something = event.params.something
       player = event.params.player
     end
  end
end

scene:addEventListener(“show”,scene)

return scene
2014-09-26 14:23:01
用户869951
用户869951

要在离开场景时移除项目,请使用 exitScene() 方法:删除事件侦听器、停止动画、暂停物理、_删除您不再需要的显示对象的引用_,等等。

对于插入到单独视图中,场景与任何其他 Lua 模块一样,因此您可以调用模块的函数进行设置:

-- yourGotoScene.lua
local value -- 告诉其他模块隐藏它

function setValue(newValue)
    value = newValue
    print('将值设置为新值:', value)
end

-- yourCallingScene.lua
...
require 'yourGotoScene'
yourGotoScene.setValue(123)
storyboard.gotoScene('yourGotoScene')
2014-09-29 03:04:00