Class Animations
Resource container for Animation resources.
The container can import animations from the JSON format exported by
Aseprite and export existing
animations back to that format. This makes it possible to author animations in Aseprite and load
them directly at runtime via Resources.animations().
Aseprite exports a sprite sheet image together with a JSON sidecar describing each frame's
location and display duration. When loading, the container expects the sprite sheet image to live
next to the JSON file (as referenced by the meta.image field). All frames must have the
same width and height; the engine's Spritesheet model is grid-based and does not support
frames of arbitrary sizes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFile extension recognised for Aseprite JSON sidecar files. -
Method Summary
Modifier and TypeMethodDescriptionbooleanexportAseprite(Animation animation, Path destinationJson) Exports the specified animation to the Aseprite JSON format.static AnimationfromAseprite(AsepriteFormat format, String animationName, URL baseUrl) Builds anAnimation(and its backingSpritesheet) from the given Aseprite model.Convenience method: returns all loaded animations indexed by name.importAseprite(String asepriteJsonPath) Convenience overload that loads an Aseprite JSON file from the runtime classpath or file system.importAseprite(Path asepriteJsonPath) Imports an Aseprite-exported animation from the given JSON file.protected AnimationLoads the resource with the specified URL.static AsepriteFormattoAseprite(Animation animation) Builds an Aseprite JSON model from the given animation.Methods inherited from class ResourcesContainer
add, add, addClearedListener, addContainerListener, clear, contains, contains, contains, count, get, get, get, get, get, get, get, getAlias, getAll, getAsync, getAsync, getResources, remove, remove, removeClearedListener, removeContainerListener, tryGet, tryGet
-
Field Details
-
ASEPRITE_FILE_EXTENSION
File extension recognised for Aseprite JSON sidecar files.- See Also:
-
-
Method Details
-
load
Description copied from class:ResourcesContainerLoads the resource with the specified URL.
This method must be implemented by subclasses to define how a resource is loaded from the given URL.
- Specified by:
loadin classResourcesContainer<Animation>- Parameters:
resourceName- The URL of the resource to be loaded.- Returns:
- The loaded resource.
- Throws:
IOException
-
importAseprite
Imports an Aseprite-exported animation from the given JSON file.
The loaded animation is registered with this container under the file name (without extension) of the JSON file. The associated sprite sheet is registered with
Resources.spritesheets().- Parameters:
asepriteJsonPath- The path to the Aseprite JSON sidecar file.- Returns:
- The imported animation.
- Throws:
IOException- If the file cannot be read or parsed, or if the referenced image cannot be loaded.
-
exportAseprite
Exports the specified animation to the Aseprite JSON format.
The sprite sheet image referenced by the animation is written next to the JSON file using the sprite sheet's name and the
.pngfile extension. The resulting.jsonfile follows the layout produced by the Aseprite CLI when exported with the--format json-hashoption.- Parameters:
animation- The animation to export.destinationJson- The path of the JSON file to write.- Returns:
trueif the export was successful;falseotherwise.
-
toAseprite
Builds an Aseprite JSON model from the given animation.- Parameters:
animation- The animation to describe.- Returns:
- The Aseprite JSON model.
-
fromAseprite
public static Animation fromAseprite(AsepriteFormat format, String animationName, URL baseUrl) throws IOException Builds an
Animation(and its backingSpritesheet) from the given Aseprite model.The image referenced by
AsepriteFormat.getImage()is resolved relative to the suppliedbaseUrland loaded via the engine's image resource container.- Parameters:
format- The Aseprite model to convert.animationName- The name to assign to the resulting animation.baseUrl- The URL used to resolve the referenced image. May benullif the image is referenced by an absolute path.- Returns:
- The created animation.
- Throws:
IOException- If the referenced image cannot be loaded or if the frames are not uniform in size.
-
getAllByName
-
importAseprite
Convenience overload that loads an Aseprite JSON file from the runtime classpath or file system.- Parameters:
asepriteJsonPath- The path to the Aseprite JSON sidecar file.- Returns:
- The imported animation.
- Throws:
IOException- If the file cannot be read or parsed, or if the referenced image cannot be loaded.
-