NineSlice

EntityVisualceramic.NineSlice (Class)

A visual divided into 9 areas to create "nine-slice" textured scalable objects.

NineSlice is a technique used to create scalable UI elements and graphics while preserving their visual integrity. The texture is divided into 9 sections:

  • 4 corners (remain at original size)
  • 4 edges (scale in one direction only)
  • 1 center (scales in both directions)

This allows creating buttons, panels, and frames that can scale to any size while keeping corners crisp and edges properly stretched or tiled.

Key features:

  • Configurable slice distances from each edge
  • Support for stretching, repeating, or mirroring the edges and center
  • Automatic handling of texture frames and rotation
  • Efficient rendering using only necessary quads

Common uses:

  • UI panels and windows
  • Scalable buttons
  • Dialog boxes and tooltips
  • Decorative frames
  • Progress bars
// Create a scalable button
var button = new NineSlice();
button.texture = assets.texture('button');
button.slice(16); // 16 pixels from each edge
button.size(200, 60); // Scale to any size

// Different slicing for each edge
var panel = new NineSlice();
panel.texture = assets.texture('panel');
panel.slice(20, 30, 40, 30); // top, right, bottom, left

// Tiled edges instead of stretched
var frame = new NineSlice();
frame.texture = assets.texture('ornate-frame');
frame.slice(32);
frame.edgeRendering = REPEAT;
frame.innerRendering = NONE; // Transparent center

Instance Members

sliceTop: Float

Distance from top border to cut slices at the top


sliceRight: Float

Distance from right border to cut slices on the right


sliceBottom: Float

Distance from bottom border to cut slices at the bottom


sliceLeft: Float

Distance from left border to cut slices on the left


innerRendering: NineSliceRendering

How to render the center section.

  • STRETCH: Scales the center to fill the area (default)
  • REPEAT: Tiles the center texture
  • MIRROR: Tiles with mirroring for seamless patterns
  • NONE: No center rendering (transparent middle)

edgeRendering: NineSliceRendering

How to render the edge sections (top, right, bottom, left).

  • STRETCH: Scales edges to fill the area (default)
  • REPEAT: Tiles the edge textures
  • MIRROR: Tiles with mirroring for seamless patterns
  • NONE: No edge rendering

texture: Texture

The texture to use for this NineSlice object


rotateFrame: Bool

Whether the texture frame is rotated 90 degrees. Used internally when working with texture atlases that pack rotated frames for optimal space usage.


Optional texture tile to use instead of a full texture. Useful when working with texture atlases where the nine-slice image is packed with other graphics.


color: Color

The tint color applied to all sections of the nine-slice. Use Color.WHITE for no tinting.


slice(value: Float): Void

Set distance from borders to cut slices. This is equivalent to slice(value, value, value, value)

Name Type Description
value Float Distance in pixels from all edges

rendering(value: NineSliceRendering): Void

Set rendering mode for both inner and edge sections.

Name Type Description
value NineSliceRendering Rendering mode to apply to all sections

computeContent(): Void

Updates the nine-slice geometry based on current size and slice settings. Called automatically when size, slices, or rendering modes change.


new(): Void

Private Members

renderingDirty: Bool

quadTop: Quad

quadRight: Quad

quadBottom: Quad

quadLeft: Quad

quadCenter: Quad

repeatTop: Repeat

repeatRight: Repeat

repeatBottom: Repeat

repeatLeft: Repeat

repeatCenter: Repeat

quadTopRight: Quad

quadBottomRight: Quad

quadBottomLeft: Quad

quadTopLeft: Quad

createCornerQuads(): Void

createCenterQuad(): Void

destroyCenterQuad(): Void

createEdgeQuads(): Void

destroyEdgeQuads(): Void

createCenterRepeat(rendering: NineSliceRendering): Void
Name Type
rendering NineSliceRendering

destroyCenterRepeat(): Void

createEdgeRepeats(rendering: NineSliceRendering): Void
Name Type
rendering NineSliceRendering

destroyEdgeRepeats(): Void

syncQuadsAndRepeats(): Void

updateRepeatTile(repeat: Repeat, texture: Texture, rotateFrame: Bool, texX: Float, texY: Float, texWidth: Float, texHeight: Float, frameX: Float, frameY: Float, frameWidth: Float, frameHeight: Float): TextureTile
Name Type
repeat Repeat
texture Texture
rotateFrame Bool
texX Float
texY Float
texWidth Float
texHeight Float
frameX Float
frameY Float
frameWidth Float
frameHeight Float
Returns
TextureTile

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()