我如何在Corona中暂停游戏场景?

我想在我的游戏中添加一个暂停按钮,而不涉及对象的物理特性。该代码仅由一些转换组成。我该如何在 corona 中实现暂停和恢复选项?

点赞
用户3131159
用户3131159

如果你只是想暂停转换,那么答案非常简单。

在你的 lua 文件顶部添加:

local gamePaused = false

然后像这样给“所有”转换添加标签:

transition.to(myObject, {time=2000, y = 768, tag = "animationBlock" } )

“标签”可以是任何友好的名称...

然后当你想暂停时,只需输入transition.pause("animationBlock")

这将停止你的动画。

为了暂停“整个”游戏,需要多一点代码但基本上相同... 首先使用上面的本地变量,然后创建一个函数,比如说“IsGamePaused”:

local function IsGamePaused()
if (gamePaused == true) then return true end
--you can add more stuff here like if (inDialog == true) then return true end
--etc. and so forth that way you have 1 function that can check all sorts of other
--information.
return false
end

然后创建一个使用上述函数暂停或恢复的函数,比如说:

if (IsGamePaused() == false) then
transition.resume("animationBlock")
else
transition.pause("animationBlock")
end
2013-12-26 15:53:47