Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
padders

Random Repeat Delay Issue

Recommended Posts

Hi Guys, 

 

I'm trying to create a timeline that has an infinite repeat, but the time between repeats is random every time (basically I've created a little timeline of some wind blowing through some plants, but I want the wind to appear random). I've done this with an eventCallback using onRepeat and a function that sets the repeatDelay every time. It's going mad though so I must be doing something wrong. I want it to play the animation through each time and then have a random amount of time between plays. My little codepen recreates the issue. Any ideas?

 

Cheers

Paul

See the Pen LqbJgG by padders1980 (@padders1980) on CodePen

Link to post
Share on other sites

Hi,

 

In general is not recommended to fiddle with the values of a GSAP instance, is better to either create it again with the new values or, in your case, use other alternatives.

 

The best approach I can think of is use a .call() method in the timeline when is completed to call a function that will restart the timeline after a random amount of time:

 

var Box = new TimelineMax({ paused: true });

Box
  .to($('#square'), 1, {rotation:45})
  .call(randomDelay)
  .play();

function randomDelay() {
  var newDelay = Math.random() * 3;
  TweenLite.delayedCall(newDelay, function() {
    Box.restart();
  });
  console.log("repeat after: ", newDelay);
};

 

Also I see @mikel here, so He's probably working on a great solution as well, so don't just take my advice and wait for His as well.

 

Happy Tweening!!

  • Like 3
Link to post
Share on other sites

That's brilliant guys, I've used a combination of both of them and it works beautifully :)

 

Thanks again.

  • Like 3
Link to post
Share on other sites

Sounds like the guys already provided solid answers but here's one more simple approach:

 

var Box = new TimelineLite({
  onComplete:function() {
    TweenLite.delayedCall(Math.random() * 3, Box.restart, null, Box);
  }
});
Box.to("#square", 1, {rotation:45});

 

  • Like 4
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.

×