createFrameDataFromId method

SpriteAnimationFrameData createFrameDataFromId(
  1. int spriteId, {
  2. required double stepTime,
})

Create a SpriteAnimationFrameData for the sprite with id spriteId from the grid.

The ids are defined as starting at 0 on the top left and going sequentially on each row.

Implementation

SpriteAnimationFrameData createFrameDataFromId(
  int spriteId, {
  required double stepTime,
}) {
  final i = spriteId % columns;
  final j = spriteId ~/ columns;
  return SpriteAnimationFrameData(
    srcPosition: Vector2Extension.fromInts(i, j)..multiply(srcSize),
    srcSize: srcSize,
    stepTime: stepTime,
  );
}