drewbit

Randomizing doesn't change in recursion

Recommended Posts

I'm trying to randomize some settings in a tween. The first time it gets random values, but each iteration thereafter is identical.

 

function RandomTween(e,o,w,h){
     TweenMax.to(e, 0, {x:(int(o.left*w)), y:(int(o.top*h)),rotation:getRandomArbitary(1.05,6.25)+"rad"});
     TweenMax.to(e, getRandomArbitary(0.5,5), {y: o.animation.to.y*h,repeat:-1,x: o.animation.to.x*w,force3D:true,
rotation:getRandomArbitary(1.05,6.25)+"rad",ease:Linear.easeNone,onComplete:function(e,o,w,h){
RandomTween(e,o,w,h);
        },onCompleteParams:[e,o,w,h]});
}
/**
 * Returns a random number between min and max
 */
function getRandomArbitary (min, max) {
    return random() * (max - min) + min;
}
var seed = 1;
function random() {
    var x = Math.sin(seed++) * 10000;
    return x - Math.floor(x);
}

 

Am I missing something here?

Share this post


Link to post
Share on other sites

It appears you are only getting random values once as your onComplete callback is applied to a tween with repeat:-1 which means the tween will repeat indefinitely and never complete.

 

From what I gather, you don't need your tween to repeat at all as each time it completes it should call that function again and generate a new tween.

 

Also it seems you are creating 2 tweens on the same target that both change the y value. Currently the second tween will kill the y part of the first tween.

Share this post


Link to post
Share on other sites

Yes indeed, thanks.

 

I had to put the second tween in side of an "onComplete" function of the first and drop the "repeat" parameter.

 

Too close to the trees... however that saying goes!  :?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.