Skip to main content

FlixelSpritemapJsonLoader

View source

class

org.flixelgdx.animation.FlixelSpritemapJsonLoader

public final class 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 optional framerate). 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.SPRITES block.
  • Adobe Animate texture atlas - the usual Animate export shape: top-level "AN" in Animation.json plus ATLAS.SPRITES in the spritemap file. Nested symbol rigs and flat document timelines are routed to FlixelAnimateRigLoader, 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)

public static FileHandle resolveAssetPath(String path)

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:

NameDescription
pathThe path to resolve. Must not be null or empty.

Returns: The resolved FileHandle. Never null.

Throws:

TypeDescription
IllegalArgumentExceptionIf the path resolves to nothing readable.

readUtf8Text(FileHandle)

public static String readUtf8Text(FileHandle f)

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:

NameDescription
fThe 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>)

public static Array<FlixelFrame> parseAtlasSprites(JsonValue spritemapRoot, Texture texture, ObjectMap<String,Integer> nameToIndexOut)

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:

NameDescription
spritemapRootThe root JSON value of the spritemap file. Must not be null.
textureThe backing texture to wrap each region around. Must not be null.
nameToIndexOutAn 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:

TypeDescription
IllegalArgumentExceptionIf ATLAS.SPRITES is missing, not an array, or contains zero entries.

load(FlixelAnimationController, String, String, String)

public static void load(FlixelAnimationController controller, String textureKey, String spritemapJsonPath, String animationJsonPath)

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:

NameDescription
controllerThe animation controller whose owning sprite should receive the loaded clips. Must not be null.
textureKeyThe asset key of the backing PNG. Must not be null.
spritemapJsonPathThe path to the spritemap JSON. Must not be null.
animationJsonPathThe path to the animation JSON. Must not be null.

Throws:

TypeDescription
IllegalArgumentExceptionIf either file is malformed, or if an Adobe Animate JSON is being loaded onto a sprite that is not a FlixelAnimateSprite.