Graphics
Immediate-mode graphics API for Ceramic, similar to Canvas 2D or Flash Graphics.
Graphics provides a familiar drawing API while efficiently managing memory through Ceramic's pooling system. It internally uses Mesh, Quad, Line, and Arc objects which are recycled between frames to minimize garbage collection.
Features:
- Basic shape drawing (rectangles, circles, polygons)
- Line and path drawing with configurable styles
- Bezier and quadratic curves
- Fill and stroke operations
- Efficient object pooling for all visuals
Example usage:
var graphics = new Graphics();
// Draw a filled rectangle
graphics.beginFill(Color.RED);
graphics.drawRect(10, 10, 100, 50);
graphics.endFill();
// Draw a stroked circle
graphics.lineStyle(2, Color.BLUE);
graphics.drawCircle(100, 100, 30);
// Draw a path
graphics.moveTo(10, 10);
graphics.lineTo(50, 30);
graphics.quadraticCurveTo(100, 20, 150, 50);
// Clear and reuse next frame
graphics.clear();
Instance Members
clear(): VoidClear all graphics and recycle visuals to pools
Set the line style for subsequent drawing operations. Call with no arguments or thickness <= 0 to disable stroking.
| Name | Type | Default |
|---|---|---|
thickness |
Float | 0 |
color |
Color | null |
alpha |
Float | 1.0 |
Begin a fill for subsequent shape operations
| Name | Type | Default |
|---|---|---|
color |
Color | null |
alpha |
Float | 1.0 |
endFill(): VoidEnd the current fill operation
Draw a rectangle
| Name | Type |
|---|---|
x |
Float |
y |
Float |
width |
Float |
height |
Float |
Draw a circle
| Name | Type | Default |
|---|---|---|
x |
Float | |
y |
Float | |
radius |
Float | |
sides |
Int | -1 |
drawArc(x: Float, y: Float, radius: Float, startAngle: Float, endAngle: Float, ?sides: Int = -1): VoidDraw an arc
| Name | Type | Default |
|---|---|---|
x |
Float | |
y |
Float | |
radius |
Float | |
startAngle |
Float | |
endAngle |
Float | |
sides |
Int | -1 |
Draw a triangle
| Name | Type |
|---|---|
x1 |
Float |
y1 |
Float |
x2 |
Float |
y2 |
Float |
x3 |
Float |
y3 |
Float |
Draw a polygon from an array of points
| Name | Type |
|---|---|
points |
Array<Float> |
Move the drawing position to a new point
| Name | Type |
|---|---|
x |
Float |
y |
Float |
Draw a line from the current position to a new point
| Name | Type |
|---|---|
x |
Float |
y |
Float |
Draw a line between two points
| Name | Type |
|---|---|
x1 |
Float |
y1 |
Float |
x2 |
Float |
y2 |
Float |
Draw a quadratic Bezier curve
| Name | Type |
|---|---|
cpx |
Float |
cpy |
Float |
x |
Float |
y |
Float |
Draw a cubic Bezier curve
| Name | Type |
|---|---|
cp1x |
Float |
cp1y |
Float |
cp2x |
Float |
cp2y |
Float |
x |
Float |
y |
Float |
drawPath(): VoidDraw all accumulated path segments
closePath(): VoidClose the current path
destroy(): Voidnew(): VoidPrivate Members
Active meshes currently being displayed
Active quads currently being displayed
Active lines currently being displayed
Active arcs currently being displayed
Pooled meshes ready for reuse
Pooled quads ready for reuse
Pooled lines ready for reuse
Pooled arcs ready for reuse
fillColor: ColorCurrent fill color
fillAlpha: FloatCurrent fill alpha
filling: BoolWhether we're currently filling
lineThickness: FloatCurrent line thickness
lineColor: ColorCurrent line color
lineAlpha: FloatCurrent line alpha
stroking: BoolWhether we have an active line style for stroking
Current path being built
currentX: FloatCurrent X position for path operations
currentY: FloatCurrent Y position for path operations
Path segments for complex shapes
currentDepth: FloatCurrent depth value for ordering visuals. Incremented for each visual added to ensure proper render order. Strokes are given higher depth than fills to render on top.
getMesh(): MeshGet a mesh from the pool or create a new one
| Returns |
|---|
| Mesh |
getQuad(): QuadGet a quad from the pool or create a new one
| Returns |
|---|
| Quad |
getLine(): LineGet a line from the pool or create a new one
| Returns |
|---|
| Line |
getArc(): ArcGet an arc from the pool or create a new one
| Returns |
|---|
| Arc |
Draw a filled rectangle using a mesh with 4 vertices.
| Name | Type |
|---|---|
x |
Float |
y |
Float |
width |
Float |
height |
Float |
Draw a stroked rectangle outline using a mesh with 8 vertices. More efficient than using 4 Line objects.
| Name | Type |
|---|---|
x |
Float |
y |
Float |
width |
Float |
height |
Float |
Metadata
| Name | Parameters |
|---|---|
:hxGen |
- |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |