TextureAtlasRegion
Represents a single image region within a texture atlas.
TextureAtlasRegion defines a rectangular area within a texture atlas page that contains a specific image. It extends TextureTile, allowing it to be directly assigned to visual objects like Quad.tile for rendering.
Key features:
- Supports trimmed sprites with offset data
- Handles rotated regions for optimal packing
- Automatic UV coordinate calculation
- Direct integration with the rendering system
The region stores both the packed dimensions (actual space used in atlas) and original dimensions (including trimmed transparent areas), enabling proper sprite alignment and collision detection.
// Get a region from atlas
var region = atlas.region("player_idle");
// Apply to a quad (basic support)
var quad = new Quad();
quad.tile = region;
// Position accounting for trim offset
quad.pos(100 + region.offsetX, 200 + region.offsetY);
// Apply to a sprite (extended support of trimmed regions with offsets, needs sprite plugin)
var sprite = new Sprite();
sprite.region = region;
Instance Members
name: StringUnique identifier for this region within the atlas.
Used to retrieve specific images from the atlas. Often matches the original image filename without extension.
atlas: TextureAtlasReference to the containing texture atlas.
Provides access to the atlas pages and other regions. Set automatically during region creation.
page: IntIndex of the texture page containing this region.
Large atlases may span multiple texture pages. Used to retrieve the correct texture for rendering.
packedWidth: IntActual width of packed pixels in the atlas.
This is the width after any rotation applied during packing. May be different from display width if the region was rotated. Used for texture coordinate calculations.
packedHeight: IntActual height of packed pixels in the atlas.
This is the height after any rotation applied during packing. May be different from display height if the region was rotated. Used for texture coordinate calculations.
x: IntX position of the region within its texture page.
Pixel coordinate from the left edge of the texture. Used to calculate texture coordinates for rendering.
y: IntY position of the region within its texture page.
Pixel coordinate from the top edge of the texture. Used to calculate texture coordinates for rendering.
width: IntDisplay width of the region (before any rotation).
This is the width of the visible pixels, excluding any transparent areas that were trimmed during packing.
height: IntDisplay height of the region (before any rotation).
This is the height of the visible pixels, excluding any transparent areas that were trimmed during packing.
offsetX: FloatHorizontal offset from original sprite origin.
When sprites are trimmed, this offset maintains proper alignment. Positive values shift the sprite right. Add to sprite X position for correct placement.
offsetY: FloatVertical offset from original sprite origin.
When sprites are trimmed, this offset maintains proper alignment. Positive values shift the sprite down. Add to sprite Y position for correct placement.
originalWidth: IntOriginal sprite width before trimming.
Includes any transparent margins that were removed during atlas packing. Use this for maintaining consistent sprite sizes and proper collision bounds.
originalHeight: IntOriginal sprite height before trimming.
Includes any transparent margins that were removed during atlas packing. Use this for maintaining consistent sprite sizes and proper collision bounds.
computeFrame(): VoidCalculates texture coordinates from pixel positions.
Converts the pixel-based region coordinates (x, y, width, height) into normalized UV coordinates for GPU rendering. This method must be called after the atlas page textures are loaded to ensure proper coordinate calculation.
The method handles:
- Texture density scaling
- Coordinate normalization (0-1 range)
- Frame property updates for rendering
Typically called automatically by TextureAtlas.computeFrames() after all pages are loaded.
new(name: String, atlas: TextureAtlas, page: Int): VoidCreates a new texture atlas region.
Typically called internally by atlas parsers and packers. Automatically registers this region with the atlas.
| Name | Type | Description |
|---|---|---|
name |
String | Unique identifier for this region |
atlas |
TextureAtlas | The containing texture atlas |
page |
Int | Index of the texture page containing this region |
Private Members
toString(): StringReturns a detailed string representation of this region.
Includes all region properties for debugging purposes: name, page index, dimensions, offsets, and texture coordinates.
| Returns | Description |
|---|---|
| String | String representation with all region data |