TweenSequence<T> constructor

TweenSequence<T>(
  1. List<TweenSequenceItem<T>> items
)

Construct a TweenSequence.

The items parameter must be a list of one or more TweenSequenceItems.

There's a small cost associated with building a TweenSequence so it's best to reuse one, rather than rebuilding it on every frame, when that's possible.

Implementation

TweenSequence(List<TweenSequenceItem<T>> items)
    : assert(items.isNotEmpty) {
  _items.addAll(items);

  double totalWeight = 0.0;
  for (final TweenSequenceItem<T> item in _items) {
    totalWeight += item.weight;
  }
  assert(totalWeight > 0.0);

  double start = 0.0;
  for (int i = 0; i < _items.length; i += 1) {
    final double end = i == _items.length - 1 ? 1.0 : start + _items[i].weight / totalWeight;
    _intervals.add(_Interval(start, end));
    start = end;
  }
}