tweenjs / tween.js

JavaScript/TypeScript animation engine
https://tweenjs.github.io/tween.js/
Other
9.85k stars 1.41k forks source link

Randomize tween target parameter on every call. #148

Closed chimaira closed 10 years ago

chimaira commented 10 years ago

Hi , Sorry , it probably not an issue, but I did not find any way for my animation case .

Here is it, I started a single tween with an infinity repeat.

    var tmpTween = new TWEEN.Tween(position)
                        .to({x: nx, y: ny}, 2000)
                        .easing(TWEEN.Easing.Linear.None)
                        .repeat(Infinity)
                        .start();

In this aimation I want the 'nx' and 'ny' values to be randomized on every tween recall, in other words I want passing expressions instead of fixed values.

How to perform that ?

Thank you.

chimaira commented 10 years ago

Hi again, Sory I solved this by calling the same function within the tween onComplete

    function fly(max, min) {
       var cx = Math.floor(Math.random() * (max - min) + min);
       var cy = Math.floor(Math.random() * (max - min) + min);
       var tmpTween = new TWEEN.Tween(scope.target)
                        .to({x: cx, y: cy}, 2000)
                        .easing(TWEEN.Easing.Linear.None)
                        .start()
                        .onComplete(function () {
                            scope.fly(10,0);
                        });
   // ....//
    };
sole commented 10 years ago

Yeah that's one option, there's nothing built-in. Closing as resolved!