Core Library - Varollo/aseprite-importer GitHub Wiki

This section explains the installation process and use of the Core module of the Library.
There are many ways to install the package, here are some:
Open your terminal of choice and past the following command:
dotnet add package AsepriteImporter
On Visual Studio, open the Package Manager Console
.
Tools > NuGet Package Manager > Package Manager Console
And paste the following command:
NuGet\Install-Package AsepriteImporter
Edit your project file (.csproj
) and paste this line:
<PackageReference Include="AsepriteImporter"/>
First, don't forget to include the code bellow at the top your file:
using Varollo.AsepriteImporter;
When you want to load a sprite sheet data file, call the method LoadJsonData
, on the AsepriteDataLoader
static class, passing in the path
to the .json
file, like this:
const string PATH = "root/directory/data.json";
private AsepriteSheet LoadMyData()
{
AsepriteSheet sheetData = AsepriteDataLoader.LoadJsonData(PATH);
return sheetData;
}
This will load the file using System.IO
and automatically parse it into a AsepriteSheet
object using the Json.Net library, by Newtonsoft.
You can also opt to parse the data through a string containing the json, using the ParseJsonData
method:
private AsepriteSheet LoadMyData()
{
string json = LoadJsonInternally();
AsepriteSheet sheetData = AsepriteDataLoader.ParseJsonData(json);
return sheetData;
}
You can read the frame data deserialized into a AsepriteSheet
object in three different ways:
One way to access all frames in the sprite sheet, is through the property Frames
, that stores in an Array the data for every frame in the sheet.
EXAMPLE:
private void LogFrameNames(AsepriteSheet sheet)
{
foreach(AsepriteFrame frame in sheet.Frames)
{
System.Console.WriteLine(frame.Name);
}
}
When you need to access a frame knowing its index in the sheet Frame array, the easiest way to get its information is through the AsepriteSheet
indexer, passing in the frame index as a parameter.
EXAMPLE:
private void LogFirstFrameName(AsepriteSheet sheet)
{
AsepriteFrame frame = sheet[0];
System.Console.WriteLine(frame.Name);
}
To filter the frames of a specific animation, you can also use the AsepriteSheet
indexer, this time, passing the Name
of the animation.
You can find more information about grouping frames of the same animation here.
EXAMPLE:
private void LogFrameNamesOfAnimation(AsepriteSheet sheet, string animationName)
{
foreach(AsepriteFrame frame in sheet[animationName])
{
System.Console.WriteLine(frame.Name);
}
}
To check if the sprite sheet contains an animation of a certain name, the simplest way is through the AsepriteSheet
method HasAnimation(string)
.
EXAMPLE:
private void LogTrueIfAnimationIsPresent(AsepriteSheet sheet, string animationName)
{
System.Console.WriteLine(sheet.HasAnimation(animationName));
}
If your .json
file contains Aseprite generated Metadata, and you need to retrieve any information from it, you can do so through the AsepriteSheet
property MetaData
.
More information about configuring the generated Metadata on Aseprite can be found on the Aseprite section.
EXAMPLE:
private void LogAsepriteVersion(AsepriteSheet sheet)
{
System.Console.WriteLine(sheet.MetaData ?? "No metadata present...");
}
To go more in depth about all the Core library's methods and classes, you may find the full documentation here.
By Varollo.