Working with sprite animation
Let's change the George
class to play an animation sequence instead of just a single frame by changing the class:
- First, change the class definition to extend from
SpriteAnimationComponent
instead ofSpriteComponent
:class George extends SpriteAnimationComponent {
- Because we are going to set up an animation within
SpriteAnimationComponent
, we can remove the references togeorgeSprite
as this will be managed by the class. So, let's remove or comment the following lines:// late Sprite georgeSprite; // georgeSprite = spriteSheet.getSprite(0, 0);
You can also remove or comment the render
function now as the drawing will be managed by the class:
// @override // void render(Canvas canvas) { // super.render(canvas); // georgeSprite.render(canvas); // }
- To create an animation from the sprite sheet we set up, the
SpriteSheet
class...