FlixelSpritemapJsonLoader
View sourceclass
org.flixelgdx.animation.FlixelSpritemapJsonLoader
Helper class for spritemap-style JSON assets. Handles two separate shapes:
- Simple animation index - a top-level
"animations": { name: { "frames": [0, 1, 2] } }block (with optionalframerate). Frames may be declared as a JSON array of[x, y, w, h, ...]rows, as an object map of frame name to{"frame": {"x", "y", "w", "h"}}, or as an Adobe "TexturePacker"ATLAS.SPRITESblock. - Adobe Animate texture atlas - the usual Animate export shape: top-level
"AN"inAnimation.jsonplusATLAS.SPRITESin the spritemap file. Nested symbol rigs and flat document timelines are routed toFlixelAnimateRigLoader, which requires the owning sprite to be a FlixelAnimateSprite.
Game code does not usually call this helper directly. A FlixelAnimateSprite accepts an Animate atlas triple through FlixelAnimateSprite.addSpritemapAndAnimation(String), and a plain FlixelSprite accepts a simple-format pair through FlixelAnimationController.loadSpritemapFromJson(...).
Methods
resolveAssetPath(String)
Resolves an asset path the same way the rest of FlixelGDX does: first Gdx.files.internal, then Gdx.files.classpath. The first hit that exists and is not a directory is returned.
Parameters:
| Name | Description |
|---|---|
path | The path to resolve. Must not be null or empty. |
Returns: The resolved FileHandle. Never null.
Throws:
| Type | Description |
|---|---|
IllegalArgumentException | If the path resolves to nothing readable. |
readUtf8Text(FileHandle)
Reads a text file as UTF-8 and strips a leading byte-order mark if present. Use for XML and JSON so the path does not fall back to the platform default charset.
Parameters:
| Name | Description |
|---|---|
f | The file handle to read from. Must not be null. |
Returns: The text content; never null (an empty file yields the empty string).
parseAtlasSprites(JsonValue, Texture, ObjectMap<String,Integer>)
Parses a spritemap JSON's ATLAS.SPRITES block (the Adobe Animate "BTA" shape) into a list of FlixelFrame instances, and fills nameToIndexOut with a lookup from sprite name to atlas index.
This method is shared between the simple and Animate loaders so that only one place knows how to unpack Adobe's name/x/y/w/h fields.
Parameters:
| Name | Description |
|---|---|
spritemapRoot | The root JSON value of the spritemap file. Must not be null. |
texture | The backing texture to wrap each region around. Must not be null. |
nameToIndexOut | An output map. Cleared on entry and filled with sprite name to atlas index for each entry that has a non-empty name. Must not be null. |
Returns: The list of built FlixelFrame regions, in declaration order.
Throws:
| Type | Description |
|---|---|
IllegalArgumentException | If ATLAS.SPRITES is missing, not an array, or contains zero entries. |
load(FlixelAnimationController, String, String, String)
Top-level entry point used by FlixelAnimationController.loadSpritemapFromJson(...). Reads both files, figures out which flavor the animation JSON is, and dispatches to the appropriate handler.
Parameters:
| Name | Description |
|---|---|
controller | The animation controller whose owning sprite should receive the loaded clips. Must not be null. |
textureKey | The asset key of the backing PNG. Must not be null. |
spritemapJsonPath | The path to the spritemap JSON. Must not be null. |
animationJsonPath | The path to the animation JSON. Must not be null. |
Throws:
| Type | Description |
|---|---|
IllegalArgumentException | If either file is malformed, or if an Adobe Animate JSON is being loaded onto a sprite that is not a FlixelAnimateSprite. |