Jump to content

Delay between tweens


Yanifska
 Share

Recommended Posts

Hi there

 

I have a character "patrol" with this tween.

 

this.myTween = game.add.tween(this).to({ x: this.x + dist },  Phaser.Timer.SECOND*patrolSpeed, Phaser.Easing.Quadratic.InOut, true, Phaser.Timer.SECOND * game.rnd.integerInRange(0.5,2), 10000, true);

 

I'd like to add a stop between each loop.

how would you go for that  ?

Link to comment
Share on other sites

Hi, look at these TweenData properties: repeatDelay and yoyoDelay. You can set it through Tween methods: repeatDelay() a yoyoDelay().

 

This is working example of "patroling" with 1 second delay:

            var sprite = this.add.sprite(100, 100, "Atlas", "Sprite", this.world);            var tween = this.add.tween(sprite);            tween.to({ x: 200 }, 1000, Phaser.Easing.Linear.None, true, 1000, -1, true);            tween.repeatDelay(1000);            tween.yoyoDelay(1000);

1000 millis delay is in tween's to() and it is first delay before tween starts. repeatDelay and yoyoDelay are there for delay before each repeat as well as before each yoyo return.

 

I also recommend to replace number of repeats (10000 in your code) with -1 (= forever)...

Link to comment
Share on other sites

thanks a lot

 

I got an error message

 

Uncaught TypeError: this.myTween.repeatDelay is not a function

 

I am on phaser 2.2.2 btw

 

and the code is located inside a prototype:

 

function Enemy1(game, X, parent, dist, patrolSpeed){   Phaser.Sprite.call(this, game, X, yPos - 80, 'guard')   //some stuffs   this.myTween = game.add.tween(this).to({ x: this.x + dist },  Phaser.Timer.SECOND*patrolSpeed, Phaser.Easing.Quadratic.InOut, true, Phaser.Timer.SECOND * game.rnd.integerInRange(0, 1.5), -1, true);   this.myTween.repeatDelay(4000);   this.myTween.yoyoDelay(4000);   this.myTween.onLoop.add(function(){ this.scale.x *= -1; }, this);}
Enemy1.prototype = Object.create(Phaser.Sprite.prototype);
Enemy1.prototype.constructor = Enemy1;

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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