Jump to content
Search Community

How to obtain elapsed time?

GusAugust test
Moderator Tag

Recommended Posts

Timeline tlA translates a rectangle horizontally three times, with constant acceleration across all three.
When tlA completes, tlB is supposed to translate the rectangle once vertically.
The sequence works properly only if I provide a position value for tlB. The value 2.5 was determined by trial and error.
The issue remains if they are made children of a parent timeline.

The repeat value will be a variable provided by the user. This means that the position value for tlB will vary and needs to be determined in code.

How can the position value be determined elegantly?

Thank you,
Gus

var rect:Sprite = new Sprite;
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(50, 75, 50, 50); // x, y, width, height
rect.graphics.endFill();
addChild(rect);

var tlA:TimelineMax = new TimelineMax();
var tlB:TimelineMax = new TimelineMax();
TweenMax.to(tlA, 5, { timeScale:20 } );
tlA.repeat(2);
tlA.to(rect, 5, { x:400 } );
tlB.to(rect, 5, { y:200}, 2.5 ); // 2.5 is trial and error value

Link to comment
Share on other sites

If your goal is to make tlB start when tlA finishes, why not just use an onComplete on tlA? Or you could add the "y" tween directly into tlA and use an onStart that kills the timeScale tween and sets the timeScale back to 1. You may be approaching this in a way that makes it a bit too complex when that's not really necessary. Then again, I may be misunderstanding your question :)

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