如何正确暂停涉及物理和过渡的游戏?

发布于 2024-11-27 00:00:26 字数 82 浏览 2 评论 0原文

我想在我的游戏中包含一个暂停按钮,其中涉及对象的物理特性和一些过渡。我如何在 Corona SDK 中做到这一点,我对它还很陌生? 有什么指导吗??

I want to include a pause button in my game which involves physics on the objects and some transitions. How can I do that in Corona SDK, to which I am fairly new?
Any guidance??

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

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

发布评论

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

评论(4

奈何桥上唱咆哮 2024-12-04 00:00:26
function pause()

physics.pause()
end

Runtime:addEventListener("touch", pause)

将暂停所有物理。

function pause(event)
    if event.phase == "began" then
        if paused == false then
             physics.pause()
             paused = true
        elseif paused == true then
             physics.start()
             paused = false
        end
   end
end

paused = false
Runtime:addEventListener("touch", pause)

单击时将切换物理暂停

function pause()

physics.pause()
end

Runtime:addEventListener("touch", pause)

will pause all physics.

function pause(event)
    if event.phase == "began" then
        if paused == false then
             physics.pause()
             paused = true
        elseif paused == true then
             physics.start()
             paused = false
        end
   end
end

paused = false
Runtime:addEventListener("touch", pause)

will toggle physics pause on click

池予 2024-12-04 00:00:26

除了停止物理之外,如果您有随场景移动的对象以及游戏中的任何动画,您还必须删除输入帧侦听器。

所以你的暂停功能会是这样的

function Pause(event)
 if event.phase == "began" then
    if paused == false then

      physics.pause()
      paused = true

      Runtime:removeEventListener("enterFrame",Contador_func)
      Runtime:removeEventListener("enterFrame",Move_c1ScrollPai)
      Runtime:removeEventListener("enterFrame",Move_c1ScrollFilho)
      Runtime:removeEventListener("enterFrame",VelAumenta)
      Runtime:removeEventListener("enterFrame",Serra)  
      Runtime:removeEventListener("enterFrame",passaro)
      Runtime:removeEventListener("enterFrame",bf)
      Runtime:removeEventListener("enterFrame",bf2) 
      Runtime:removeEventListener("enterFrame",p)        
      Runtime:removeEventListener("enterFrame",CR)        
      Runtime:removeEventListener("enterFrame",Funcao)
      Runtime:removeEventListener("enterFrame",BumPassaro)
      Runtime:removeEventListener("collision",Andar)

      p:pause()
      Bum:pause()
      coin:pause()
      coins:pause()

    elseif paused == true then

      Runtime:addEventListener("enterFrame",Contador_func)
      Runtime:addEventListener("enterFrame",Move_c1ScrollPai)
      Runtime:addEventListener("enterFrame",Move_c1ScrollFilho)
      Runtime:addEventListener("enterFrame",VelAumenta)
      Runtime:addEventListener("enterFrame",Serra)  
      Runtime:addEventListener("enterFrame",passaro)
      Runtime:addEventListener("enterFrame",bf)
      Runtime:addEventListener("enterFrame",bf2) 
      Runtime:addEventListener("enterFrame",p)        
      Runtime:addEventListener("enterFrame",CR)        
      Runtime:addEventListener("enterFrame",Funcao)
      Runtime:addEventListener("enterFrame",BumPassaro)
      Runtime:addEventListener("collision",Andar)
      Runtime:removeEventListener("enterFrame",p)

      p:play()
      Bum:play()
      coin:play()
      coins:play()

      physics.start()
      paused = false

    end
 end
 end

Besides stopping physics, you also have to remove the enterframe listeners, if you have objects that moves with the scene, and any animation you have in the game.

So your pause function would be like that

function Pause(event)
 if event.phase == "began" then
    if paused == false then

      physics.pause()
      paused = true

      Runtime:removeEventListener("enterFrame",Contador_func)
      Runtime:removeEventListener("enterFrame",Move_c1ScrollPai)
      Runtime:removeEventListener("enterFrame",Move_c1ScrollFilho)
      Runtime:removeEventListener("enterFrame",VelAumenta)
      Runtime:removeEventListener("enterFrame",Serra)  
      Runtime:removeEventListener("enterFrame",passaro)
      Runtime:removeEventListener("enterFrame",bf)
      Runtime:removeEventListener("enterFrame",bf2) 
      Runtime:removeEventListener("enterFrame",p)        
      Runtime:removeEventListener("enterFrame",CR)        
      Runtime:removeEventListener("enterFrame",Funcao)
      Runtime:removeEventListener("enterFrame",BumPassaro)
      Runtime:removeEventListener("collision",Andar)

      p:pause()
      Bum:pause()
      coin:pause()
      coins:pause()

    elseif paused == true then

      Runtime:addEventListener("enterFrame",Contador_func)
      Runtime:addEventListener("enterFrame",Move_c1ScrollPai)
      Runtime:addEventListener("enterFrame",Move_c1ScrollFilho)
      Runtime:addEventListener("enterFrame",VelAumenta)
      Runtime:addEventListener("enterFrame",Serra)  
      Runtime:addEventListener("enterFrame",passaro)
      Runtime:addEventListener("enterFrame",bf)
      Runtime:addEventListener("enterFrame",bf2) 
      Runtime:addEventListener("enterFrame",p)        
      Runtime:addEventListener("enterFrame",CR)        
      Runtime:addEventListener("enterFrame",Funcao)
      Runtime:addEventListener("enterFrame",BumPassaro)
      Runtime:addEventListener("collision",Andar)
      Runtime:removeEventListener("enterFrame",p)

      p:play()
      Bum:play()
      coin:play()
      coins:play()

      physics.start()
      paused = false

    end
 end
 end
能怎样 2024-12-04 00:00:26

使用Physics.pause(),物理对象中会有轻微的抖动

另一种方法是在暂停时捕获屏幕并将其放在场景上。

之后,将暂停的屏幕 GUI 对象放在屏幕顶部。

恢复时删除暂停的屏幕对象和屏幕截图。

local gameScene= display.newGroup()

local myObject1 = display.newRect(50,50,100,150 )
gameScene:insert(myObject1)

function onPause(event)
    local screenCap = display.captureScreen(false) --dont save to album
    gameScene:insert(screenCap)

    --insert pause buttons and etc here
end

Runtime:addEventListener("touch",onPause)

With physics.pause() there will be a slight jitter in the physics object.

Another way is to capture the screen when paused and put it over the scene.

After that you put on top of the screen the paused screen GUI objects.

Remove the paused screen objects and the screen capture when resume.

local gameScene= display.newGroup()

local myObject1 = display.newRect(50,50,100,150 )
gameScene:insert(myObject1)

function onPause(event)
    local screenCap = display.captureScreen(false) --dont save to album
    gameScene:insert(screenCap)

    --insert pause buttons and etc here
end

Runtime:addEventListener("touch",onPause)
命比纸薄 2024-12-04 00:00:26

使用暂停按钮设置功能:

local function pausebtn(event)

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

   end
pausebtn:addEventListener("touch", pausebtn)

Use pause button to set function:

local function pausebtn(event)

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

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