Class AsepriteFormat
public final class AsepriteFormat
Java representation of the JSON export format produced by Aseprite.
The Aseprite CLI can export a sprite sheet image together with a JSON sidecar that describes how each frame of the sprite sheet is laid out and how long it should be displayed. See the Aseprite CLI documentation for details.
This class supports both the "hash" (frames as an object map) and the "array" (frames as a JSON array) layouts. When writing, the engine emits the "hash" form, which is the Aseprite default.
Serialization is delegated to JsonUtilities, which is backed by the Jakarta JSON
Processing and Jakarta JSON Binding APIs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescribes a single rectangular region within an Aseprite sprite sheet. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetApp()getImage()intintstatic AsepriteFormatParses an Aseprite JSON document from the given JSON string.static AsepriteFormatReads an Aseprite JSON document from the given URL.static AsepriteFormatReads an Aseprite JSON document from the given path.voidvoidvoidvoidsetImageHeight(int imageHeight) voidsetImageWidth(int imageWidth) voidsetVersion(String version) voidWrites this Aseprite document to the given path as a (pretty-printed) JSON file.writeToString(boolean pretty) Writes this Aseprite document as a JSON string.
-
Constructor Details
-
AsepriteFormat
public AsepriteFormat()Creates an empty Aseprite format instance.
-
-
Method Details
-
read
Reads an Aseprite JSON document from the given URL.- Parameters:
url- The URL of the JSON file.- Returns:
- The parsed Aseprite format.
- Throws:
IOException- If the file cannot be read or parsed.
-
read
Reads an Aseprite JSON document from the given path.- Parameters:
path- The path to the JSON file.- Returns:
- The parsed Aseprite format.
- Throws:
IOException- If the file cannot be read or parsed.
-
parse
Parses an Aseprite JSON document from the given JSON string.- Parameters:
json- The JSON text.- Returns:
- The parsed Aseprite format.
- Throws:
IOException- If the JSON is malformed or does not represent an Aseprite document.
-
write
Writes this Aseprite document to the given path as a (pretty-printed) JSON file.- Parameters:
path- The destination path.- Throws:
IOException- If writing fails.
-
writeToString
Writes this Aseprite document as a JSON string.- Parameters:
pretty- Whether to format the output with indentation and line breaks.- Returns:
- The JSON representation.
-
getFrames
- Returns:
- The list of frames defined by this document.
-
getImage
- Returns:
- The image filename referenced in the document's meta block (may be
null).
-
setImage
-
getImageWidth
public int getImageWidth()- Returns:
- The width of the referenced sprite sheet image, in pixels.
-
setImageWidth
public void setImageWidth(int imageWidth) -
getImageHeight
public int getImageHeight()- Returns:
- The height of the referenced sprite sheet image, in pixels.
-
setImageHeight
public void setImageHeight(int imageHeight) -
getFormat
- Returns:
- The pixel format string from the document's meta block.
-
setFormat
-
getApp
-
setApp
-
getVersion
-
setVersion
-