2013-10-18 67 views
0

我在退出/查殺/退出我的requestAnimationFrame時遇到了問題。我的gameloop工作,我可以暫停我的遊戲(gameloop保持活躍)。但是當我想返回到我的菜單時,我想殺死requestAnimationFrame,因此它會停止繪圖和更新。我在網上搜索和計算器上,發現了類似的問題,試圖TE響應,但沒有運氣:(無法停止requestAnimationFrame(Javascript/html5:canvas)

var fps = 60; 
var now; 
var then = Date.now(); 
var interval = 1000/fps; 
var delta; 

//============================================================================ 

function gameloop(){ 
window.requestAnimationFrame(gameloop); 

if (game.isUnpaused()){ 
//game is not paused, update all 
     now = Date.now(); 
      delta = now - then; 

       if (delta > interval) { 
        then = now - (delta % interval); 
       //DO ALL WHAT'S NEEDED: draw avatar,move obstacles,move avatar.... 
        }} 

//what to do when game is paused: 
else{//draw stuff when game is paused} 

} 

任何人可以幫助我

在此先感謝

回答

2
var active = true; 
function gameloop(){ 
    if(active){ 
     window.requestAnimationFrame(gameloop); 
     } 
    } 
+0

非常感謝? )你的我的英雄;) – Bosiwow