Quad
The most basic and commonly used visual for displaying rectangles and images.
Quad is a specialized Visual that renders a rectangular shape which can be:
- A solid colored rectangle
- A textured rectangle (displaying an image)
- A portion of a texture (using frame coordinates)
Features:
- Color tinting
- Texture/image display
- Frame-based texture regions (for sprite sheets)
- Transparency control
- Texture tile support
- Automatic size from texture
Quads are the building blocks for most 2D visuals in Ceramic. They're optimized for performance and batched together when possible.
// Create a colored rectangle
var rect = new Quad();
rect.size(100, 50);
rect.color = Color.RED;
rect.pos(10, 10);
// Create a textured quad
var image = new Quad();
image.texture = assets.texture('hero');
image.anchor(0.5, 0.5);
image.pos(screen.width * 0.5, screen.height * 0.5);
// Use a portion of a texture
var sprite = new Quad();
sprite.texture = assets.texture('spritesheet');
sprite.frame(32, 64, 16, 16); // x, y, width, height
Instance Members
color: Color
The color to tint this quad. Default is WHITE (no tinting). The color is multiplied with the texture colors if a texture is set. Use this to tint images or create colored rectangles.
transparent: Bool
If set to true
, this quad will be considered
transparent and won't be drawn on screen.
This only affects this quad's rendering - children
are still drawn normally (transparency is not inherited).
Useful for invisible containers or temporarily hiding quads.
tile: TextureTile
A texture tile defining a region of a texture to display. When set, automatically configures the texture and frame properties. Useful for working with texture atlases and sprite sheets. Setting this to null clears the texture.
texture: Texture
The texture (image) to display on this quad. When set, the quad's size is automatically updated to match the texture size unless a tile or frame is specified. Setting to null makes the quad display as a solid color. The texture's asset reference count is automatically managed.
frameX: Float
The X coordinate of the texture region to display. Used with frameWidth/frameHeight to display a portion of the texture. -1 means no frame is set (display entire texture).
frameY: Float
The Y coordinate of the texture region to display. Used with frameWidth/frameHeight to display a portion of the texture. -1 means no frame is set (display entire texture).
frameWidth: Float
The width of the texture region to display. When set, also updates the quad's display width. -1 means no frame is set (use full texture width).
frameHeight: Float
The height of the texture region to display. When set, also updates the quad's display height. -1 means no frame is set (use full texture height).
rotateFrame: Bool
Whether the texture frame should be rotated 90 degrees. Used internally by texture packing systems to optimize atlas space. Most users won't need to set this directly.
destroy(): Void
Set the texture frame coordinates and size in one call. Useful for displaying a specific region of a texture (sprite sheets).
Name | Type | Description |
---|---|---|
frameX |
Float | X coordinate in the texture |
frameY |
Float | Y coordinate in the texture |
frameWidth |
Float | Width of the region to display |
frameHeight |
Float | Height of the region to display |
isRegular(): Bool
Returns true
if this quad is a regular rectangle.
A quad is regular if it has no rotation or skew transformations.
Regular quads can be rendered more efficiently in some cases.
Returns | Description |
---|---|
Bool | True if the quad is axis-aligned without skew |
new(): Void
Create a new Quad. The quad starts with no texture (solid color) and must be sized and positioned after creation.
Private Members
FLAG_TRANSPARENT: Int
FLAG_ROTATE_FRAME: Int
computeMatrix(): Void
Name | Type |
---|---|
_ |
Entity |
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |