# Kill tween and put another tween to the same target

**URL:** <https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096>\
**Category:** Phaser 3\
**Created:** [August 11, 2021, 3:08pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096 "2021-08-11T15:08:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![celinebeaumont](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@celinebeaumont](https://phaser.discourse.group/u/celinebeaumont)\
**Post date:** [August 11, 2021, 3:08pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/1 "2021-08-11T15:08:18Z")

</div>

Hello everyone  
I get stuck by stopping the tween applied to a sprite and trying to applied another tween to the same sprite.  
Here is a simplyfied example of my problem (using a example in [phaser.io](http://phaser.io))

```javascript
var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('block', 'assets/sprites/block.png');
}

function create ()
{
    var image = this.add.image(100, 300, 'block');

    var tween = this.tweens.add({
        targets: image,
        x: 700,
        delay: 1000,
        duration: 6000,
        ease: 'Power2'
    });

    this.input.on('pointerdown', function () {

        tween.stop();//tween.destroy() doesn't work
        tween = this.tweens.add({
            targets: image,
            y:0,
            delay: 1000,
            duration: 6000,
            ease: 'Power2'

        });
        

    });
}

```

the first tween works well, but the game freezes when clicking on mouse button, failling to apply the second tween.  
Does someone have an idea about how to do ?

---

<div class="post-metadata">

**Author:** ![celinebeaumont](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@celinebeaumont](https://phaser.discourse.group/u/celinebeaumont)\
**Post date:** [August 11, 2021, 3:18pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/2 "2021-08-11T15:18:25Z")

</div>

It functions for the example if I put

```javascript
this.input.on('pointerdown', function () {....}, this);

```

but it is not exactely the probleme in my program  
I try to put another example

---

<div class="post-metadata">

**Author:** ![celinebeaumont](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@celinebeaumont](https://phaser.discourse.group/u/celinebeaumont)\
**Post date:** [August 11, 2021, 4:22pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/3 "2021-08-11T16:22:01Z")

</div>

I have isolated my problem, sorry for the delaying.  
Here is it

```javascript
class sceneA extends Phaser.Scene {
    constructor() {
                    super({key:"sceneA"});
                  }
    preload(){
        this.load.image('block', 'assets/button1.png');
    }
    create(){
        
        this.block = new Block(this,100,300);
       
        this.input.once(Phaser.Input.Events.POINTER_DOWN, function () {
  
         this.block.changeMove();
    
        },this);
        
    
        this.add.text(20,20,"Example!");
  
   
    }

  }

  class Block extends Phaser.GameObjects.Sprite{
    constructor(scene,posx,posy){
    
      super(scene, posx, posy,"block");
      scene.add.existing(this);

      this.tween = scene.tweens.add({
        targets: this,
        x: 600,
        paused: false,
        yoyo: true,
        repeat: -1
      });
    
    }

    changeMove(){
        this.tween.stop();
        this.tween = scene.tweens.add({
                                        targets: this,
                                        y: 0,
                                        paused: false,
                                        yoyo: true,
                                        repeat: -1
                                    });

    }
  }

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: [sceneA]
};

var game = new Phaser.Game(config);

```

the first tween works well, but when pressing mouse button, it freezes  
Does someone knows how to fix it ?

---

<div class="post-metadata">

**Author:** ![celinebeaumont](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@celinebeaumont](https://phaser.discourse.group/u/celinebeaumont)\
**Post date:** [August 11, 2021, 4:59pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/4 "2021-08-11T16:59:01Z")

</div>

found it.  
In constructor of Block, if I put

```javascript
this.scene = scene

```

and in the method changeMove

```javascript
this.tween = this.scene.tweens.add({});

```

it works  
The post is solved.

---

<div class="post-metadata">

**Author:** ![rich](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rich/32/4_2.png) [@rich](https://phaser.discourse.group/u/rich)\
**Post date:** [August 11, 2021, 5:39pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/5 "2021-08-11T17:39:14Z")

</div>

Glad you solved it, but it’s worth adding that you do not need:

```javascript
this.scene = scene;

```

In your Block Game Object, because it extends Sprite and the call to `super()` will do that automatically. That line of code is basically just repeating something that has already happened.

---

<div class="post-metadata">

**Author:** ![celinebeaumont](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@celinebeaumont](https://phaser.discourse.group/u/celinebeaumont)\
**Post date:** [August 11, 2021, 5:56pm UTC](https://phaser.discourse.group/t/kill-tween-and-put-another-tween-to-the-same-target/10096/6 "2021-08-11T17:56:14Z")

</div>

Thank you, rich, to point that
