Jump to content
GreenSock

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

infinite animation stops looping on reverse

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

 

So i have multiple dom elements that i animate along an svg path ... for now ... looping clockwise works ... it loops forever

but if i call reverse() .... it acts like a rewind() ... if it repeated twice ... it will reverse only 2 times .. not forever

 

var timeLine = new TimelineMax({
    repeat: -1,
    paused: false,
    yoyo: true
});

 

timeLine.add(TweenMax.to(arrPeople[i], totalTime, {
            bezier: {
                type: "cubic",
                autoRotate: true,
                values: points
            },
            force3D: true,
            repeat: -1,
            yoyo: true,
            ease: Power0.easeNone,
            onUpdate: function() {
                if (this.target == arrPeople[0] && !initialized) {
                    let children = timeLine.getChildren();
                    if (children[0].time() >= totalTime - totalTime / people.length / 2) {
                        timeLine.paused(true);
                        initialized = true;
                    }
                }
            }
        }), (i + 1) * totalTime / people.length);

 

this is the code i use to create the timeline and the tweens

 

any sugestions? :(

 

thanks

Link to comment
Share on other sites

5 hours ago, Wowzaaa said:

any sugestions? :(

 

A demo would help. It's very hard to troubleshoot an animation without seeing it. 

 

  • Like 1
Link to comment
Share on other sites

Hi @Wowzaaa

 

I must say, I'm even more confused now. I see a bunch of SVG related stuff in your code, and references to different SVG libraries like d3 and snap, but it doesn't look like you're using any SVGs.

 

I also don't see the issue you described above. I see a bunch of people spin around a desk, and then it stops. No reverse or looping behavior is happening and I don't see any controls or buttons that work.

 

I guess a better question would be what are you trying to do? To do that rotation animation, you certainly don't need to use a Bezier,  or create a custom path only to have another library parse it so you can convert it to an array of points.

 

I can think of a bunch of different ways to do that rotation and that staggered fanning out behavior, but I'm really not sure what the issue and the desired outcome are. Can you describe in more detail some of these things?

 

  • Like 2
Link to comment
Share on other sites

Thanks. Now I see what you're talking about.

 

Quick question, once all the people spread out around the circle, do they ever go back to their starting position? If not, I think this could be simplified a lot.

  • Like 1
Link to comment
Share on other sites

they should keep their place at the table ... what i will need to do after i fix this .. is to

1) make the table turn back and forth on mouse scroll

2) make the number of people dynamic ... that is why i build the svg on the fly ... when there are 100 people ... it won't be a circle ... it will turn into an oval (or a rectangle with rounded corners with a radius of width / 2) ... so the visible part will still look like half a circle ... but the invisible part will not look like now

 

thanks

Link to comment
Share on other sites

Ah, ok. What I was thinking about will only work for a circle, so scratch that. I'll just rework your timeline. In the meantime, here's some info about creating cubic Beziers. Converting a rounded rectangle to cubic Beziers isn't too hard.

 

For lines, you set the first control point at 1/3 the distance, the second control point at 2/3 the distance, and the anchors are of course at the ends. So if you had a horizontal line that was 30px long, the points would be at 0, 10, 20, and 30.

 

For an arc, multiply this number by the radii to get the distances of the control points.

var kappa = 0.551915024494;

 

See the Pen oZxobX by osublake (@osublake) on CodePen

 

 

  • Like 3
Link to comment
Share on other sites

thanks for the info ... makes much more sense now

 

one question though ... are u telling me that my current solution for building the path will not work?

function roundedRect(x, y, width, height, radius) {
    return "M" + x + "," + (y + 0)
        + "a" + radius + "," + radius + " 0 0 1 " + radius + "," + -radius
        + "h" + (width - 2 * radius)
        + "a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius
        + "v" + (height - 2 * radius)
        + "a" + radius + "," + radius + " 0 0 1 " + -radius + "," + radius
        + "h" + (2 * radius - width)
        + "a" + radius + "," + radius + " 0 0 1 " + -radius + "," + -radius
        + "z";
}

 

i tested this and it does what i supposed to ... but maybe u are talking about the conversion to cubic Beziers ... if my path structure is ok .. wouldn't TweenMax follow it whatever shape it might have?

 

thanks

Link to comment
Share on other sites

The code for your path looks fine. But that's not going to visible, right? Isn't it just for the motion path?

 

If so, I was suggesting to just skip that part as it's unnecessary, and you won't need to use snap. You can just grab the points for the Bezier tween doing what I described above. I can show you how if that doesn't make sense.

 

  • Like 1
Link to comment
Share on other sites

Quote

The code for your path looks fine. But that's not going to visible, right? Isn't it just for the motion path?

 

right

 

Quote

If so, I was suggesting to just skip that part as it's unnecessary, and you won't need to use snap. You can just grab the points for the Bezier tween doing what I described above. I can show you how if that doesn't make sense.

 

i think i understand .... but ... i use that because i plan to just give my shape a width and height ... and get the path back ... this is the first time i work with Bezier so building them dynamically is a bit ... unknown to me :) at this point at least :)

 

are u telling me that my roundedRect function can return directly the bezier points?

 

thanks

Link to comment
Share on other sites

Yeah, working with Beziers can take some time getting used to. I'll set that function up for you, so all you will have to do is pass in your rounded rect params, and it will return the Bezier object for the tween.

  • Like 1
Link to comment
Share on other sites

so can u at least give me a suggestion on how to fix my original issue? the one with reverse?

 

thanks

Link to comment
Share on other sites

Hi @Wowzaaa

 

Sorry for not getting back to you. I reworked your demo, but had to leave before I got a chance to post it. I'll show you it when I get back home in a couple hours.

 

  • Like 1
Link to comment
Share on other sites

much appreciated :)

 

do u also have a suggestion for using the mouse wheel to rotate the people back and forth around the table?

 

thanks

Link to comment
Share on other sites

Yeah. You can use the delta value from wheel event to change the progress of the animation. Shouldn't be too hard to implement. I'll take a look at the get when I get back home.

  • Like 1
Link to comment
Share on other sites

i saw some examples online but all use jQuery's scrollTop();

 

my specific case is that body has overflow hidden ... so the is no actual scroll for the page :)

Link to comment
Share on other sites

so can anyone point me in the right direction? i do not need the whole solution ... i just need to understand what am i doing wrong ... what am i missing?

Link to comment
Share on other sites

i'm sure he would answer me if he could but i was hopping there was someone else that can show me the error of my ways :)

Link to comment
Share on other sites

I said I would help you out, but had other priorities to take care of first. 

 

If you got it working, then great. You can close your issue on Github too.

 

I was going to recommend a different approach once I realized you were trying to make it work like a conveyor belt. Having 100, DOM based animations running at the same time with a linear ease is not a good idea. If there's a framerate drop, it's going to be painfully obvious. Something that might contribute to a framerate drop is the fact that at least 50% those animations will be out of view, making it very inefficient.

 

I was going to suggest what I originally had in mind, position everything around a large div, and spin that div so there is only 1 animation, similar to this demo. It's also draggable, which means it will work with mobile.

 

 

 

You can simulate the conveyor belt effect by placing all your characters on the div, and toggling their visibility. It wouldn't be to hard to figure out which characters should be visible based based on the rotation of the div. 

 

 

  • Like 3
Link to comment
Share on other sites

And in case anybody else needs help with looping part of a timeline, you can isolate the loop in another animation.

 

var someAnimation = new TimelineMax({ repeat: 1 })
  ...

var loopAnimation = new TimelineMax({ repeat: -1 })
  .add(someAnimation.tweenFromTo(timeAfterOneLoop, timeAfterOneLoop + durationOfLoop))

 

I do the same thing in this demo.

 

See the Pen YrXdGZ by osublake (@osublake) on CodePen

 

 

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