Jump to content
Search Community

Issue with object resetting after timeline call

FARIOA test
Moderator Tag

Go to solution Solved by PointC,

Recommended Posts

Hi,

I am relatively new to greensock, but I am trying to have the block maintain it's rotation and movement in between calls of spin instead of having the block reset every time. How would I go about this? I thought the to method moves from the object's current location?

Thanks in advance. 

See the Pen GRQGJdr by gstops (@gstops) on CodePen

Link to comment
Share on other sites

Hi @FARIOA,

 

Welcome to the forum.

 

You'd want to use relative values for that. This will add a new tween to the timeline on each click.

let spin = function () {
  spinSquare.to(".outer", {
    duration: 1,
    delay: 0.5,
    ease: "power1",
    rotation: "+=45",
    x: "+=200"
  });
};

Keep in mind that you are adding a new tween to the timeline on each click, but you're also playing the timeline from 0 each click as well so it still jumps back to the beginning.

 

See the Pen 29bacc336e2b6b66474c023dfc2cba7a by PointC (@PointC) on CodePen

 

Happy tweening.

:)

 

  • Like 1
Link to comment
Share on other sites

Thank you @PointC! My mind totally missed relative values. That would certainly do the trick. However, I realized that I missed something small in my codepen. In my actual project, I put a ,0 after the "to" method to set it to the first spot in the timeline. I don't want to run the animation repeatedly in the timeline, instead, I want to have the object save the rotation amount so that it starts from there each time I click spin. I coded it as such because in my actual project, I use a random value for the amount of rotation that takes a couple of variables, so the spin amount changes each time. How would I go about this? Let me know if you need more information about it, or if you would like me to create another codepen for it.

Link to comment
Share on other sites

@PointC Yep. That would be EXACTLY what I'm looking for. You're a lifesaver, and also quite possibly a mind reader. (No clue how you understood what I meant and found the method I needed). I know who to ask if I have more questions...

 

Thank you so much for your help!

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