Change tween target on tween repeat

I have a button flashing and I am trying to update the tween to swap to another flashing button randomly - is it possible to use the same tween to swap targets? I did try to directly edit the tweens target though that did not work (buttonFlash.targets = etc...)

  const buttonFlash = this.tweens.add({
    targets: squares[Phaser.Math.Between(0, 2)],
    duration: speed,
    alpha: 0,
    yoyo: true,
    repeat: -1,
    onRepreat: () => { 
     // Update target here
    },
  })
1 Like

I would just add a new tween.

2 Likes

Thanks! I have gone for that approach.

  let difficulty = 8;
  const speed = 500;

  const buttonFlash = {
    targets: squares[Phaser.Math.Between(0, 2)],
    duration: speed,
    alpha: 0,
    yoyo: true,
    onComplete: () => {
      difficulty--;
      if (difficulty) this.tweens.add({ ...buttonFlash, targets: squares[Phaser.Math.Between(0, 2)] })
    }
  }

  this.tweens.add(buttonFlash)

Changing the tween targets directly works if you assign it an array.

In your case it would be a single element array.
buttonFlash.targets = [ squares[Phaser.Math.Between(0, 2)] ];