2011-07-28 45 views

回答

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

隨着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) 
1

使用暫停按鈕來設置功能:

local function pausebtn(event) 

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

    end 
pausebtn:addEventListener("touch", pausebtn) 
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