In phaser 3 framework, what syntax do I use to check the current frame index?
I want to make a hit area appear only when the player’s sprite sheet reaches a certain index(the index displaying the motion of ‘attack’). I want to accomplish this through detecting its current frame index.
How can I do this?
Advertisement
Answer
The solution is found. //hitbox solution: https://newdocs.phaser.io/docs/3.52.0/Phaser.Animations.Events.ANIMATION_COMPLETE_KEY
JavaScript
x
16
16
1
//hitboxB listener
2
gameState.playerB.on('animationstart-kill', function () {
3
console.log("finish kill <3")
4
gameState.hitBoxB.x = gameState.playerB.flipX ? gameState.playerB.x + 120 : gameState.playerB.x - 120;
5
gameState.hitBoxB.y = gameState.playerB.y;
6
// gameState.hitBoxB.visible = true;
7
8
})
9
gameState.playerB.on('animationcomplete-kill', function () {
10
console.log("kill <3")
11
gameState.hitBoxB.x =0 ;
12
gameState.hitBoxB.y = 0;
13
// gameState.hitBoxB.visible = false;
14
15
})
16