The MonoGame.Extended.Animations library contains classes useful for animating 2D sprite.
MonoGame.Extended.Animations is distributed via a NuGet package. You can add the NuGet package to your C# project through your IDE of choice (Visual Studio, Xamarin Studio, Rider, etc) or through the Command Line Interface (CLI) using the dotnet command.
In this example we use SpriteFactory for animating Sprites. we are going to build it ourselves from the source.
Step 1 clone the SpriteFactory repository
git clone https://github.com/craftworkgames/SpriteFactory.git
Step 2 Build and run
dotnet run --project SpriteFactory
Creating the Animation
The assets used in this example can be downloaded here
Before we can load an animation, we must first animate it in SpriteFactory.
We are using the
mowt.png from the assets
Create new project in
File -> New
Open mowt.png in
Step 3 Set Tile Size to 52 by 72 pixels
Step 4 Add your animations and configure your prefered Frame duration
Next we save our animation as
SpriteFactory animation does not have to be imported with the ContentPipeline
But we de need to tell the compiler to copy
mowt.sf to the output folder.
In visual studio you can do that by clicking on
mowt.sf in the Solution Explorer and setting
Copy to Output Directorty to
Copy if newer.
You can also set this in your
project.csproj by adding the following
motw.png can just be imported as Texture2D.
Loading the Animation
We start by defining our fields
Next we load the content
new JsonContentLoader() you need to use the
Updating the Animation
We use the following code to update the Position and Animation of the Player.