FlixelFrame
View sourceclass
org.flixelgdx.graphics.FlixelFrame
Frame wrapper around a libGDX TextureRegion.
This carries the extra metadata needed for Sparrow/atlas frames (original size and offsets), similar to libGDX's TextureAtlas.AtlasRegion, but without depending on an atlas type.
Why these extra fields exist
Sparrow (Starling) atlases ship trimmed frames: transparent borders are cut away to pack more art into the texture. To draw a trimmed frame where the artist intended, the frame remembers how big the art was before trimming (FlixelFrame.originalWidth/FlixelFrame.originalHeight, called the "source size") and where the trimmed pixels sit inside that original box (FlixelFrame.offsetX/FlixelFrame.offsetY). Anchoring every frame to its source box is what keeps an animated character's feet planted while individual frames change shape.
The static FlixelFrame.regionInsetX(...) and FlixelFrame.regionInsetY(...) helpers turn that metadata into the pixel offset at which the trimmed region should be drawn inside the source box. They are pure functions (no libGDX state) so the geometry can be unit tested without a GPU texture.
Constructors
FlixelFrame(TextureRegion)
Constructs a new FlixelFrame with the given region.
Parameters:
| Name | Description |
|---|---|
region | The region to wrap. |
Throws:
| Type | Description |
|---|---|
NullPointerException | If the provided region is null. |
Fields
name
Optional frame name (used by Sparrow prefix animations).
originalWidth
Width of the original, untrimmed frame in pixels (Sparrow's frameWidth). For frames that were never trimmed this equals FlixelFrame.getRegionWidth().
originalHeight
Height of the original, untrimmed frame in pixels (Sparrow's frameHeight).
offsetX
Horizontal offset (in pixels) from the source frame's left edge to the trimmed region's left edge. This is the negation of Sparrow's frameX (offsetX = -frameX), so a frame trimmed 13 pixels from the left (frameX = -13) stores offsetX = 13. Always measured from the top-left of the source box, matching the image's natural orientation.
offsetY
Vertical offset (in pixels) from the source frame's top edge to the trimmed region's top edge, the negation of Sparrow's frameY (offsetY = -frameY).
rotated
Whether this frame was packed into its atlas rotated 90 degrees clockwise.
When true, Adobe Animate stores the sprite sideways in the PNG to save space. The backing TextureRegion covers the on-disk footprint as-is (width = logical height, height = logical width), while FlixelFrame.originalWidth and FlixelFrame.originalHeight always hold the logical (pre-rotation) dimensions. The rig baker applies a rotation-correction matrix so the part renders upright in rig space regardless of how it was packed.
Methods
regionInsetX(int, int, int, boolean)
Computes where the trimmed region's left edge sits inside the source box, in pixels measured from the box's left edge.
When the frame is not horizontally flipped this is simply FlixelFrame.offsetX. When it is flipped, the art mirrors around the source box's vertical center line, so the left and right trim gaps swap: the new left inset becomes whatever empty space used to sit on the right (sourceWidth - regionWidth - offsetX). Mirroring around the source box (rather than the trimmed region) is what keeps a left-facing pose lined up with its right-facing counterpart.
Parameters:
| Name | Description |
|---|---|
sourceWidth | The untrimmed frame width (FlixelFrame.originalWidth). |
regionWidth | The trimmed region width (FlixelFrame.getRegionWidth()). |
offsetX | The left trim offset (FlixelFrame.offsetX). |
flipX | Whether the frame is drawn mirrored horizontally. |
Returns: The left inset of the region inside the source box, in pixels.
regionInsetY(int, int, int, boolean)
Computes where the trimmed region's bottom edge sits inside the source box, in pixels measured upward from the box's bottom edge.
The renderer works in a y-up space (larger y is higher on screen), so a region is positioned by its bottom-left corner. The unflipped bottom inset is the empty space below the art inside the source box (sourceHeight - regionHeight - offsetY); keeping it constant across an animation's frames is exactly what plants a character's feet. A vertical flip swaps the top and bottom gaps, leaving FlixelFrame.offsetY as the new bottom inset.
Parameters:
| Name | Description |
|---|---|
sourceHeight | The untrimmed frame height (FlixelFrame.originalHeight). |
regionHeight | The trimmed region height (FlixelFrame.getRegionHeight()). |
offsetY | The top trim offset (FlixelFrame.offsetY). |
flipY | Whether the frame is drawn mirrored vertically. |
Returns: The bottom inset of the region inside the source box, in pixels.