Disable old object after the new appears

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 :smiley:.

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

http://labs.phaser.io/edit.html?src=src\time\timer%20event.js

function firearrowL(){
    if (arrowshot) {
var  sprite_arrow =  arrow.create(player.x, player.y, 'arrow');
   sprite_arrow.setVelocityX(800);
 arrowshot = false
  this.time.delayedCall( 2000, function() {
           sprite_arrow.destroy()
                  }
}

And you must pass “this” inside function, otherwise " this.time.delayedCall" will not work.
This is how you shoud call function :

firearrowL.call(this);

Thank you so, it was useful. Your program works but only once, after the arrow does not appear. It’s not a big deal, I’ll fix it easily.
(You forgot to close the function and the delayedCall btw)
Thanks again. :smiley: