Spellthorn / pixel_adventure

A Flutter and Flame project to make the game Pixel Adventure, a 2D Pixel Art Platformer.
129 stars 42 forks source link

Reduce animation loading boilerplate. #9

Open darrenaustin opened 7 months ago

darrenaustin commented 7 months ago

Thanks again for the great series. I noticed that there was a lot of unnecessary boilerplate used to load the animations for the Player and Chicken classes. This PR refactors this to remove the unused fields that stores the animations. As they are only ever referenced in the animations map, they are just cluttering up the class. If they are ever needed for something else in the future, they can be pulled from the animations map.

In addition it is a good practice to declare the type you are using to specify the animations in the map:

class Player extends SpriteAnimationGroupComponent<PlayerState>

That way the compiler can help you with warnings if you try to use something other than a PlayerState for current.