Phaser3 框架 javascript:当前动画索引

Phaser3 framework javascript: current anims index

在phaser 3框架中,我使用什么语法来检查当前帧索引?

我想只在玩家的精灵 sheet 达到某个索引(显示 'attack' 动作的索引)时才出现命中区域。我想通过检测其当前帧索引来完成此操作。

我该怎么做?

您可以使用如下精灵事件:Phaser.Animations.Events.ANIMATION_UPDATEdetails in official phaser documenation

    player.on(Phaser.Animations.Events.ANIMATION_UPDATE, function (anim, frame, gameObject, frameKey) {
       // Here you can check for the specific-frame
       if(frameKey == "show_hit_area_frame"){
           // ... show hitarea
       }

       // alternatively: with the index of the frame
       if(frame.index == 7){
           // ... show hitarea
       }
    });

在此选中的事件中,您还可以检查当前帧,以获取帧对象的其他属性(details in official documenation),如果您不know/have具体framekey/index .

已找到解决方案。 //hitbox解决方案:https://newdocs.phaser.io/docs/3.52.0/Phaser.Animations.Events.ANIMATION_COMPLETE_KEY

//hitboxB listener
    gameState.playerB.on('animationstart-kill', function () {
      console.log("finish kill <3")
      gameState.hitBoxB.x = gameState.playerB.flipX ? gameState.playerB.x + 120 : gameState.playerB.x - 120;
      gameState.hitBoxB.y = gameState.playerB.y;
      // gameState.hitBoxB.visible = true;

    })
    gameState.playerB.on('animationcomplete-kill', function () {
      console.log("kill <3")
      gameState.hitBoxB.x =0 ;
      gameState.hitBoxB.y = 0;
      // gameState.hitBoxB.visible = false;
      
    })