TextureTile
Defines a rectangular sub-region within a texture for rendering.
TextureTile represents a portion of a texture that can be rendered independently, similar to a sprite frame. It's commonly used for:
- Texture atlas regions
- Sprite sheet frames
- Tiled textures
- UI element slicing
The tile can be assigned to visual objects like Quad.tile to render only the specified portion of the texture. Supports rotation for optimally packed texture atlases and edge insets to prevent bleeding.
// Create a tile from a sprite sheet
var spriteSheet = assets.texture('characters.png');
var playerTile = new TextureTile(
spriteSheet,
0, 0, // Top-left corner
32, 48, // 32x48 sprite
false, 0.5 // No rotation, 0.5 pixel inset
);
// Apply to a quad
var player = new Quad();
player.tile = playerTile;
player.size(32, 48);
Instance Members
texture: Texture
The source texture containing this tile.
References the full texture from which this tile extracts its rectangular region. Must be a valid loaded texture for the tile to render.
frameX: Float
X coordinate of the tile's top-left corner in the texture.
Measured in texture pixels from the texture's origin. Combined with frameWidth defines the horizontal bounds.
frameY: Float
Y coordinate of the tile's top-left corner in the texture.
Measured in texture pixels from the texture's origin. Combined with frameHeight defines the vertical bounds.
frameWidth: Float
Width of the tile region in texture pixels.
Defines how many pixels wide to sample from the texture starting at frameX. Should not exceed texture bounds.
frameHeight: Float
Height of the tile region in texture pixels.
Defines how many pixels tall to sample from the texture starting at frameY. Should not exceed texture bounds.
rotateFrame: Bool
Whether this tile is rotated 90 degrees in the texture.
Used by texture packers to fit more images by rotating them. When true, the tile's width and height are swapped during rendering to display correctly. Common in optimized atlases.
edgeInset: Float
Pixel inset applied to tile edges during rendering.
Shrinks the UV coordinates by this amount to prevent texture bleeding between adjacent tiles in an atlas. Useful values:
- 0: No inset (default)
- 0.5: Half-pixel inset (common for atlases)
- 1.0: Full pixel inset (for problematic cases)
The inset is applied in texture space, not screen space.
Updates the tile's frame coordinates.
Convenience method to update all frame properties at once. Does not affect texture, rotation, or inset settings.
Name | Type | Description |
---|---|---|
frameX |
Float | New X coordinate in texture pixels |
frameY |
Float | New Y coordinate in texture pixels |
frameWidth |
Float | New width in texture pixels |
frameHeight |
Float | New height in texture pixels |
new(texture: Texture, frameX: Float, frameY: Float, frameWidth: Float, frameHeight: Float, ?rotateFrame: Bool = false, ?edgeInset: Float = 0): Void
Creates a new texture tile.
Name | Type | Default | Description |
---|---|---|---|
texture |
Texture | Source texture containing the tile | |
frameX |
Float | X coordinate in texture pixels | |
frameY |
Float | Y coordinate in texture pixels | |
frameWidth |
Float | Width in texture pixels | |
frameHeight |
Float | Height in texture pixels | |
rotateFrame |
Bool | false |
Whether tile is rotated 90 degrees (default: false) |
edgeInset |
Float | 0 |
Pixel inset for edge bleeding prevention (default: 0) |
Private Members
toString(): String
Returns a string representation of this tile.
Includes texture reference and frame coordinates for debugging. Rotation and inset values are not included in the output.
Returns | Description |
---|---|
String | String with tile properties |
Metadata
Name | Parameters |
---|---|
:structInit |
- |