我在退出/杀死/退出我的 requestAnimationFrame 时遇到问题。我的游戏循环工作,我可以暂停我的游戏(游戏循环保持活跃)。但是当我想返回我的菜单时,我想杀死 requestAnimationFrame,所以它停止绘制和更新。我在互联网和 stackoverflow 上搜索过,发现类似的问题尝试了响应,但没有运气:(
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}
}
有谁能够帮我?
提前致谢