Jump to content
Search Community

Random Repeat Delay Issue

padders test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

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 comment
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 comment
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.
×
×
  • Create New...