Phase3框架javascript:当前动画索引



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

我想只有当玩家的精灵表达到某个索引(显示"攻击"动作的索引(时,才会显示命中区域。我想通过检测它的当前帧索引来实现这一点。

我该怎么做?

您可以使用sprite事件,如:Phaser.Animations.Events.ANIMATION_UPDATE,官方相位器文档中的详细信息

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
}
});

在这个选定的事件中,如果您不知道/没有特定的帧键/索引,您还可以检查当前帧,以了解帧对象的其他属性(详细信息请参阅官方文档(。

找到了解决方案。//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;

})

最新更新