I'm starting to develop in Phaser 3, and I'm really a begginer.
I'm trying to make an attack move of an archer sprite, but I cannot make it work right...
This is how I have defined the things related to combat:
class Jugador extends Phaser.Physics.Arcade.Sprite {
constructor(escena, x, y) {
super(escena, x, y, "jugador");
this.escena = escena;
this.escena.add.existing(this);
this.escena.physics.add.existing(this);
this.createVariables();
this.createControls();
this.createAnimations();
}
createAnimations(){
this.defineAttackAnimation();
/// Some others...
}
defineAttackAnimation(){
this.attackAnimation = {};
this.attackAnimation.key = "attack";
this.attackAnimation.frames =
this.escena.anims.generateFrameNames("attack",
{
prefix: "attack",
start: 1,
end: 6
});
this.attackAnimation.frameRate = this.attackFrameRate;
this.attackAnimation.repeat = 1;
var atkListener = () => {
this.arrow();
};
this.escena.anims.create(this.attackAnimation);
this.escena.anims.get("attack")
.addListener("animationcomplete", atkListener);
}
arrow(){
console.log("arrow");
}
attack(){
if(this.body.onFloor() && this.attackButton.isDown){
this.setVelocityX(0);
this.setVelocityY(0);
this.play("attack", true);
}
}
update() {
if ( this.body.onFloor() ){
this.setVelocityY(0);
}
this.facing();
this.idle();
this.walk();
this.jump();
this.attack();
if (this.body.velocity.y < 0){
this.play("jump");
} else if (this.body.velocity.y > 0 && !this.body.onFloor()){
this.play("falling");
}
}
}
What I want to do is:
- Player pushes the attack button.
- Attack animation plays. I would like it to be played untill it ends, but now I have to keep pushing the attack button.
- When attack animation ends, the function "arrow" is executes in order to make an arrow appear.
Thanks in advance.