play method
Plays row from the given frame, or whichever row key names.
// Animates the third row from its start.
sprite.play(row: 2);
// Animates whichever row the sprite calls 'jump'.
sprite.play(key: 'jump');
loop overrides what the row states, until the next call. It also clears
isFinished, so a non-looping sprite that already finished runs again
from wherever this puts it.
Implementation
void play({
T? key,
int row = 0,
int frame = 0,
bool? loop,
}) {
assert(key == null || row == 0, 'Must supply a key or a row, but not both.');
if (key != null) {
final named = _sprite.rowOf(key);
if (named == null) {
throw ArgumentError.value(key, 'key', 'No such row.');
}
row = named;
}
if (row < 0) {
throw ArgumentError.value(row, 'row', 'Cannot be negative.');
}
if (row >= _sprite.rows) {
throw ArgumentError.value(row, 'row', 'Only ${_sprite.rows} rows available.');
}
if (frame < 0) {
throw ArgumentError.value(frame, 'frame', 'Cannot be negative.');
}
final frames = _sprite.frames(row);
if (frame >= frames) {
throw ArgumentError.value(frame, 'frame', 'That row only plays $frames frames.');
}
_row = row;
_frame = frame;
_loop = loop;
_elapsed = 0;
_finished = false;
_source = null;
_destination = null;
}