Skip to content

Instantly share code, notes, and snippets.

@AlabasterAxe
Created November 9, 2020 23:55
Show Gist options
  • Select an option

  • Save AlabasterAxe/a11412ca49559aeed6e73c1cc65e09bc to your computer and use it in GitHub Desktop.

Select an option

Save AlabasterAxe/a11412ca49559aeed6e73c1cc65e09bc to your computer and use it in GitHub Desktop.
Adding a run animation to our dinosaur.
class Dino extends GameObject {
int frame = 1;
@override
Widget render() {
return Image.asset(
"assets/images/dino/dino_$frame.png",
gaplessPlayback: true,
);
}
@override
Rect getRect(Size screenSize, double runDistance) {
return Rect.fromLTWH(
screenSize.width / 10,
4 / 7 * screenSize.height - dino.imageHeight,
dino.imageWidth.toDouble(),
dino.imageHeight.toDouble());
}
@override
void update(Duration lastTime, Duration elapsedTime) {
frame = (elapsedTime.inMilliseconds / 100).floor() % 2 + 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment