我想在我的游戏中加入一个暂停按钮,它包含物体上的物理和一些过渡。我怎么能在Corona SDK中做到这一点,我相当新? 任何指导??
答案 0 :(得分:4)
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)
将点击
切换物理暂停答案 1 :(得分:2)
除了停止物理外,如果有随场景移动的对象,以及游戏中的任何动画,你还必须删除enterframe监听器。
所以你的暂停功能就像那样
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
答案 2 :(得分:1)
使用physics.pause()时,物理对象中会有轻微的 jitter 。
另一种方法是在暂停时捕捉屏幕并将其放在场景上。
之后,您将暂停的屏幕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)
答案 3 :(得分:1)
使用暂停按钮设置功能:
local function pausebtn(event)
if event.phase == "ended" then
physics.pause()
end
pausebtn:addEventListener("touch", pausebtn)