Osiris Posted June 7, 2021 Share Posted June 7, 2021 Hello, can anyone explain to me, why the following is not working (repeat needs to be added when the tween is already declared)? var myTween = gsap.to(object, {duration: 1, opacity: 0, paused: true}) myTween["vars"]["repeat"] = -1; myTween.play(); I believe the above approach is valid, because when i write the following just before i call myTween.play() myTween["vars"]["onComplete"] = function(){console.log("completed")} i can see the console output "completed", when the animation is complete. I don't understand, why myTween["vars]["repeat] = -1 does not do anything. If i call console.log(myTween) after the "repeat" thing is declared, i can see it's added in the vars object already. Link to comment Share on other sites More sharing options...
OSUblake Posted June 7, 2021 Share Posted June 7, 2021 Changing repeat needs to be done internally, so that won't work. You should use the repeat method. https://greensock.com/docs/v3/GSAP/Tween/repeat() 16 minutes ago, Osiris said: I believe the above approach is valid, because when i write the following just before i call myTween.play() myTween["vars"]["onComplete"] = function(){console.log("completed")} That's a little different than changing the repeat logic, as it's just calling what's on the vars object. A cleaner way to do that is with the eventCallback method. https://greensock.com/docs/v3/GSAP/Tween/eventCallback() Generally, messing with the vars object isn't going to change anything unless you invalidate the animation. Also note that those methods are also available on timelines. The full docs for Tweens and Timelines can be found here. https://greensock.com/docs/v3/GSAP/Tween https://greensock.com/docs/v3/GSAP/Timeline 3 Link to comment Share on other sites More sharing options...
Osiris Posted June 8, 2021 Author Share Posted June 8, 2021 Thanks. And don't mess with the vars object, got it. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now