暂停移相器动画

Pause phaser animation

我注意到即使

game.pause = true

暂停游戏并停止更新周期,所有动画继续播放。这在循环动画中尤其烦人,因为它更明显。

有没有一种方法可以暂停所有 运行 动画,而无需明确保留它们的列表并暂停它们 'manually'?

要暂停所有动画,您首先要将这些动画添加到 中,然后暂停该组。这是使用 group.

暂停所有动画的示例代码
      var game = new Phaser.Game(800,600,Phaser.CANVAS,' ',{
    preload: preload, create: create
});


    function preload(){
        game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
        // Note : load spritesheet without xml file

    }

var coins;
var flag = null;

    function create(){

        coins = game.add.group();

        for(var i=0;i<50;i++){
            coins.create(game.world.randomX,game.world.randomY,'coin',false);    
        }
        // NOTE : now using the power of callAll we can add same animation to all coins in the group
        coins.callAll('animations.add', 'animations', 'spin', [0,1,2,3,4,5], 10, true);
        // NOTE : the key should be 'animations' and the last param 'true' means repeatable

        coins.callAll('animations.play', 'animations', 'spin');

        var spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
        spaceKey.onDown.add(pauseGame,this);
        flag = false;

    }

    function pauseGame(){
      if(flag == false){
            game.paused = true;
            flag = true;
        }
        else if(flag == true){
            game.paused = false;
            flag = false;
        }
    }

使用空格键暂停和播放所有动画。