Repeat
A visual component that repeats a texture pattern to fill a specified area.
The Repeat class efficiently tiles a texture (or texture region) across a rectangular area, creating patterns like tiled backgrounds, repeating borders, or texture fills. It automatically manages Quad instances from an object pool to minimize memory allocation and improve performance.
Key features:
- Automatic texture tiling in X and/or Y directions
- Optional mirroring for seamless patterns
- Spacing between tiles
- Efficient object pooling of Quad instances
- Support for TextureTile regions
Example usage:
// Create a repeating background pattern
var background = new Repeat();
background.texture = assets.texture("pattern");
background.size(screen.width, screen.height);
background.spacing(2, 2); // 2px gap between tiles
// Create a horizontally repeating border
var border = new Repeat();
border.tile = atlas.get("border_segment");
border.size(400, 32);
border.repeatY = false; // Only repeat horizontally
// Create a mirrored pattern for seamless tiling
var seamless = new Repeat();
seamless.texture = assets.texture("tile");
seamless.mirror(true, true); // Mirror in both directions
seamless.size(800, 600);
Performance note: The class reuses Quad instances from a pool, so creating and destroying Repeat objects frequently has minimal performance impact.
Instance Members
Array of Quad instances used to render the repeated pattern. Managed automatically by the class - do not modify directly.
spacingX: Float
Horizontal spacing between repeated tiles in pixels. Positive values create gaps between tiles.
spacingY: Float
Vertical spacing between repeated tiles in pixels. Positive values create gaps between tiles.
repeatX: Bool
Whether to repeat the texture horizontally. When false, the texture is stretched to fill the width instead of tiling.
repeatY: Bool
Whether to repeat the texture vertically. When false, the texture is stretched to fill the height instead of tiling.
mirrorX: Bool
Whether to mirror alternate tiles horizontally. Creates a seamless pattern by flipping every other column.
mirrorY: Bool
Whether to mirror alternate tiles vertically. Creates a seamless pattern by flipping every other row.
texture: Texture
The texture to repeat across the area. Setting this will clear any previously set tile.
rotateFrame: Bool
Whether the texture frame is rotated 90 degrees. Used internally for texture atlas optimization.
tile: TextureTile
A texture tile (region) to repeat instead of a full texture. Setting this will automatically update the texture and frame properties.
color: Color
The color tint applied to all repeated tiles. White (0xFFFFFF) means no tinting.
Sets spacing between tiles. @overload function(value:Float):Void Sets both X and Y spacing to the same value @overload function(spacingX:Float, spacingY:Float):Void Sets X and Y spacing independently
Name | Type |
---|---|
value |
Float |
Controls texture repetition. @overload function(value:Bool):Void Enable/disable repetition in both directions @overload function(repeatX:Bool, repeatY:Bool):Void Control X and Y repetition independently
Name | Type |
---|---|
value |
Bool |
Controls texture mirroring for seamless patterns. @overload function(value:Bool):Void Enable/disable mirroring in both directions @overload function(mirrorX:Bool, mirrorY:Bool):Void Control X and Y mirroring independently
Name | Type |
---|---|
value |
Bool |
computeContent(): Void
Recomputes the tiled pattern based on current properties. Called automatically when properties change.
new(): Void
Creates a new Repeat instance. Initializes with a single Quad that will be replicated as needed.
Private Members
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |