Jump to content

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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