Hello, I’m new here (and french too, sorry for the note).
I create a game with phaser 3 and I want to know how to delete or disable an arrow after a defined time or a new arrow shoot.
here’s my (terribly written) code .
arrow = this.physics.add.group();
arrow2 = this.physics.add.group();
arrowUp = this.physics.add.group();
if (keys.T.isDown){
if (keys.Q.isDown){
firearrowL();
this.sound.play('accord1', sfxconfig);}
else if(keys.D.isDown){
firearrow();
this.sound.play('accord1', sfxconfig);
}
else
{
firearrowUp();
this.sound.play('accord1', sfxconfig);}
}
var timeout = null;
var arrowshot = true;
function firearrow(){
if (arrowshot) {
arrow.create(player.x, player.y, 'arrow');
arrow.setVelocityX(800);
arrowshot = false
clearTimeout(timeout);
timeout = setTimeout(() => { arrowshot = true}, 800);
}
}
function firearrowL(){
if (arrowshot) {
arrow.create(player.x, player.y, 'arrow2');
arrow.setVelocityX(-800);
arrowshot = false
clearTimeout(timeout);
timeout = setTimeout(() => { arrowshot = true}, 800);
}
}
function firearrowUp(){
if (arrowshot) {
arrow.create(player.x, player.y, 'arrowUp');
arrow.setVelocityY(-800);
arrowshot = false
clearTimeout(timeout);
timeout = setTimeout(() => { arrowshot = true}, 800);
}
}