Jump to content

Tweening random values in a loop


lastnightsparty
 Share

Recommended Posts

Hi, I've been trying to tween my sprite to random x and y co-ordinates in a loop, but after the initial random values are set it just loops between them instead of generating new random values. Anyone know how to solve this problem??

 

this.add.tween(this.sprite).to( { x: this.rnd.realInRange(-100, 100) }, 1000, Phaser.Easing.Linear.None)
   .to( { y: this.rnd.realInRange(-100, 100) }, 1000, Phaser.Easing.Linear.None)
   .loop()
   .start();
Link to comment
Share on other sites

Hello, I've not tried it myself, but I believe that once the initial tween is created you won't get any new values assigned, it will just continue to loop with the values it got randomly the first time. If you want to continue having it randomly tween, you don't want to loop the tween itself, but create tweens over and over again with different values to get the affect you want. You could use a timer that fires a custom function to do what you are looking for.

Link to comment
Share on other sites

Thanks Orbital,

 

That's what I did. Wrapped it in a loop function:

 

loopTween: function(){
this.add.tween(this.sprite).to({ x: this.rnd.realInRange(-100, 100) }, 1000, Phaser.Easing.Quadratic.None)
   .to({ y: this.rnd.realInRange(-100, 100) }, 1000, Phaser.Easing.Quadratic.None)
   .start()
   .onComplete.add(this.loopTween, this);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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