GSAP - Timelines: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
Zeile 1: Zeile 1:
 +
https://greensock.com/docs/v3/GSAP/gsap.timeline()
 
  https://greensock.com/forums/topic/12643-master-timeline-and-the-use-of-functions/
 
  https://greensock.com/forums/topic/12643-master-timeline-and-the-use-of-functions/
 
== Master Timeline ==
 
== Master Timeline ==

Version vom 8. April 2022, 13:25 Uhr

https://greensock.com/docs/v3/GSAP/gsap.timeline()
https://greensock.com/forums/topic/12643-master-timeline-and-the-use-of-functions/

Master Timeline

Gutes Vorgehen für flexiblen Einsatz:

Celli, I read you question a little differently. it seems you are already using a modular approach, it's just that you are doing

var first = new TImelineLite();
var second = new TimelineLite();
var third = new TimelineLite();

master.add(first);
master.add(second);
master.add(third);

and want to know why its better to do

function getFirst() {
  var tl = new TimelineLite();
  tl.to(...)
  return tl;
}

function getSecond() {
  var tl = new TimelineLite();
  tl.to(...)
  return tl;
}

function getThird() {
  var tl = new TimelineLite();
  tl.to(...)
  return tl;
}

master.add(getFirst());
master.add(getSecond());
master.add(getThird());

The end result of both techniques is going to be identical and both offer a modular approach. However, wrapping your timelines in a function has two advantages which may not be applicable all the time, but its nice to have them:)

1: By using functions to create your timelines, you can create them "on-demand" only when needed. In the context of a large game or application the function-wrapped way means you don't have to create 500 timelines in advance, you can just call the proper function when you need a timeline.

2: You can create the same timeline multiple times and add each unique copy of the timeline to the same or any parent timeline. Although it isn't always necessary, it is very easy to use the function-wrapped technique to do

master.add(getFirst());
master.add(getFirst());
master.add(getFirst());
master.add(getSecond());
master.add(getSecond());

When it comes to doing elaborate, dynamic scene changes (based on user interaction) it makes things incredibly flexible.

Imagine your app has a variety of scenes, and each scene has its own timeline for animating in and out.

You could do something like:

navTimeline.add(scene1Out());
navTimeline.add(scene3In(), "-=1");

which would trigger the timeline that the scene3In() function generates 1 second before the scene1Out animation ends.

and then maybe later the user wants to go back to scene1

navTimeline.add(scene3Out());
navTimeline.add(scene1In(), "-=1");

The end result of this technique is that you can generate your transition timelines whenever you need them, as many times as you need them, and glue them together in any number of ways.


function carMove(){
var tl = new TimelineMax();
tl.to("#car", 2, {x:"+=200"})
/* more tweens go here */
return tl;
}

function wheelsRotate(){
var tl = new TimelineMax();
tl.to("#wheels", 2, {rotation:"+=360"})
/* more tweens go here */
return tl;
}

masterTL
.add( carMove())
.add( wheelsRotate());