Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Tweens and binding?


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

I have a couple of tweens inside a class, and I'm trying to bind one of the tween to the other tweens onComplete function, in order to restart it.

I can't however get this to work. Is this possible or is my setup completely wrong?

        this.tween1 = game.Tween.add(this.sprite, {
           x: 640,
           y: 640
        }, 2000, {
            easing: 'Quadratic.In'
        }).start();
        
        this.tween2 = game.Tween.add(this.sprite, {
           x: x,
           y: y
        }, 2000, {
            easing: 'Quadratic.Out'
        }).onComplete(function() {
           this.start(); 
        }.bind(this.tween1)).stop();
    },
    
    update: function() {
        
        var distance = this.sprite.position.distance(game.scene.playerShip.sprite.position);
        if (distance < 128 + 128) {
            this.tween1.stop();
            this.tween2.start();
        }
    }

 

Link to comment
Share on other sites

@Ninjadoodle

Ah, well you can use pause and resume functions. Or then if you need for the tween to start from beginning, then you need to create new one.

    startTween1: function() {
        this.tween1 = game.Tween.add(this.sprite, {
           x: 640,
           y: 640
        }, 2000, {
            easing: 'Quadratic.In'
        }).start();
    },
    
    startTween2: function() {
        this.tween2 = game.Tween.add(this.sprite, {
           x: x,
           y: y
        }, 2000, {
            easing: 'Quadratic.Out',
            onComplete: this.startTween1.bind(this)
        }).start();
    },
    
    update: function() {
        var distance = this.sprite.position.distance(game.scene.playerShip.sprite.position);
        if (distance < 128 + 128) {
            this.tween1.stop();
            this.startTween2();
        }
    }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...