Documentation
¶
Overview ¶
Package sprite defines the visual components: one component per visual concept - Sprite for textures and sheet regions, Text for text, and Primitive for geometry.
Each component is plain data with JSON tags and holds asset IDs, never runtime pointers; asset resolution happens in the render collector. An entity may carry components from more than one kind - a Sprite and a Text, say - and each contributes its own draw item. Each kind permits at most one component per entity, per the world's one-value-per-type rule.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircleShape ¶
type CircleShape struct {
// Radii are the circle's horizontal and vertical radii in world units.
Radii geom.Vector2
}
CircleShape is a circle centered on the drawn position, or an ellipse when its radii differ. Its fill or outline comes from the item's style.
type DrawShape ¶
type DrawShape interface {
// contains filtered or unexported methods
}
DrawShape is a geometry value used by the render pipeline's dispatch list. Implementations are RectShape, CircleShape, and LineShape. Shapes are not components: components spell geometry as Primitive data, and the collector builds these values when it resolves a frame.
type LineShape ¶
type LineShape struct {
// From is the segment's start point relative to the drawn position.
From geom.Vector2
// To is the segment's end point relative to the drawn position.
To geom.Vector2
}
LineShape is a segment whose endpoints are relative to the drawn position.
type Primitive ¶
type Primitive struct {
// Shape selects the geometry.
Shape Shape `json:"shape"`
// Rect is the rectangle's width and height in world units (ShapeRect).
Rect geom.Vector2 `json:"rect,omitempty"`
// Radii are the circle's horizontal and vertical radii in world units
// (ShapeCircle).
Radii geom.Vector2 `json:"radii,omitempty"`
// From is the segment's start relative to the position (ShapeLine).
From geom.Vector2 `json:"from,omitempty"`
// To is the segment's end relative to the position (ShapeLine).
To geom.Vector2 `json:"to,omitempty"`
// Style holds the visual style.
Style Style `json:"style,omitempty"`
}
Primitive draws geometry: a rectangle, a circle, or a line segment, with fill or outline from Style.
The zero value is valid and draws nothing. Authoring a shapeless primitive in file content is a mistake; see Primitive.Authored.
type RectShape ¶
type RectShape struct {
// Size is the rectangle's width and height in world units.
Size geom.Vector2
}
RectShape is a rectangle centered on the drawn position. Its fill or outline comes from the item's style.
type Shape ¶
type Shape uint8
Shape selects the geometry a Primitive draws. Its zero value is ShapeNone. The wire identities below are contracts: renaming one is a breaking change.
const ( // ShapeNone draws nothing. It is the zero value. ShapeNone Shape = iota // ShapeRect draws a rectangle of Rect size centered on the position. ShapeRect // ShapeCircle draws a circle with Radii centered on the position, or an // ellipse when the radii differ. ShapeCircle // ShapeLine draws a segment with From and To endpoints relative to the // position. ShapeLine )
func (Shape) MarshalJSON ¶
MarshalJSON writes the shape as its wire identity.
func (*Shape) UnmarshalJSON ¶
UnmarshalJSON reads a shape from its wire identity. It returns an error for an unknown identity.
type Sprite ¶
type Sprite struct {
// Asset is the texture ID, or the sheet document ID when Region is set.
Asset asset.ID `json:"asset,omitempty"`
// Region is the sheet region to draw. An empty value selects the whole
// texture named by Asset.
Region string `json:"region,omitempty"`
// Style holds the visual style.
Style Style `json:"style,omitempty"`
}
Sprite draws an image: a whole texture named by Asset, or, when Region is set, the named Region of the sheet document named by Asset. Region presence selects the source: an empty Asset draws nothing.
The zero value is valid and draws nothing. Authored file content may not omit the asset; see Sprite.Authored.
type Style ¶
type Style struct {
// Outline strokes a primitive's border instead of filling it. It requires a
// positive StrokeWidth and has no effect on non-primitive components.
Outline bool `json:"outline,omitempty"`
// StrokeWidth is the outline width in world units. It must not be
// negative and must be positive when Outline is set.
StrokeWidth float64 `json:"strokeWidth,omitempty"`
// Color tints texture pixels or sets the text or primitive color. A nil
// value leaves textures untinted, defaults text to white, and defaults
// primitives to black; an RGBA with zero alpha is explicitly transparent.
Color *color.RGBA `json:"color,omitempty"`
// Layer orders sprites from back to front, from 0 through 31.
Layer uint8 `json:"layer,omitempty"`
// SortOrder orders visuals within a layer; higher values draw on top.
// Equal values are ordered by world Y.
SortOrder int8 `json:"sortOrder,omitempty"`
// Hidden excludes the component from collection.
Hidden bool `json:"hidden,omitempty"`
// FlipH mirrors Sprite's texture or sheet region horizontally; text
// and primitives are not flipped.
FlipH bool `json:"flipH,omitempty"`
// FlipV mirrors Sprite's texture or sheet region vertically.
FlipV bool `json:"flipV,omitempty"`
}
Style controls sprite ordering, color, outline, flips, and visibility. The zero value is a visible, plain sprite on layer 0.
type Text ¶
type Text struct {
// Asset is the ID of the font asset to render with.
Asset asset.ID `json:"asset,omitempty"`
// Text is the single line to draw. Empty text draws nothing.
Text string `json:"text,omitempty"`
// TextSize is the font size in pixels before scaling.
TextSize float64 `json:"textSize,omitempty"`
// Style holds the visual style.
Style Style `json:"style,omitempty"`
}
Text draws one line of text centered on the entity's position, using the font named by Asset. The entity's transform scale applies to TextSize.
The zero value is valid and draws nothing.