lastnightsparty Posted November 4, 2014 Share Posted November 4, 2014 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 More sharing options...
Orbital Game Studios Posted November 4, 2014 Share Posted November 4, 2014 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. lastnightsparty 1 Link to comment Share on other sites More sharing options...
lastnightsparty Posted November 4, 2014 Author Share Posted November 4, 2014 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 More sharing options...
jflowers45 Posted November 5, 2014 Share Posted November 5, 2014 lastnightpartry, Just to be sure - your new approach solved your problem right? I just tried it on my end at seems to work fine lastnightsparty 1 Link to comment Share on other sites More sharing options...
Recommended Posts