addTransform method

int addTransform({
  1. required Rect source,
  2. RSTransform? transform,
  3. bool flip = false,
  4. Color? color,
})

Add a new batch item using a RSTransform.

The source parameter is the source location on the atlas.

You can position, rotate, scale and flip it on the canvas using the transform and flip parameters.

The color parameter allows you to render a color behind the batch item, as a background color.

The add method may be a simpler way to add a batch item to the batch. However, if there is a way to factor out the computations of the sine and cosine of the rotation so that they can be reused over multiple calls to this constructor, it may be more efficient to directly use this method instead.

Implementation

int addTransform({
  required Rect source,
  RSTransform? transform,
  bool flip = false,
  Color? color,
}) {
  final handle = _allocateHandle();

  final batchItem = BatchItem(
    source: source,
    transform: transform ??= defaultTransform ?? RSTransform(1, 0, 0, 0),
    flip: flip,
    color: color ?? defaultColor,
  );

  if (flip && useAtlas && _flippedAtlasStatus.isNone) {
    _makeFlippedAtlas();
  }

  final slot = _batchItems.length;

  _handleToSlot[handle] = slot;
  _slotToHandle.add(handle);

  _batchItems.add(batchItem);
  _sources.add(_resolveSourceForAtlas(batchItem));
  _transforms.add(batchItem.transform);

  // If color is not explicitly provided, store transparent.
  _colors.add(color ?? _defaultColor);

  return handle;
}