sprite

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

func (Primitive) Authored

func (p Primitive) Authored() error

Authored reports an error when the primitive has no shape. File content must name one; runtime zero values stay legal.

func (Primitive) Validate

func (p Primitive) Validate() error

Validate reports whether the primitive and its style are valid.

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

func (s Shape) MarshalJSON() ([]byte, error)

MarshalJSON writes the shape as its wire identity.

func (Shape) String

func (s Shape) String() string

String returns the wire identity of the shape.

func (*Shape) UnmarshalJSON

func (s *Shape) UnmarshalJSON(data []byte) error

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.

func (Sprite) Authored

func (s Sprite) Authored() error

Authored reports an error when the sprite has no asset. File content must name one; runtime zero values stay legal.

func (Sprite) Validate

func (s Sprite) Validate() error

Validate reports whether the sprite's source and style are valid. An empty Asset draws nothing; a set Region requires a sheet-valid Asset.

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.

func (Style) Validate

func (st Style) Validate() error

Validate reports an error if the layer or stroke width is invalid.

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.

func (Text) Authored

func (t Text) Authored() error

Authored reports whether the text is acceptable as authored file content: file text requires a font. Runtime zero values stay legal.

func (Text) Validate

func (t Text) Validate() error

Validate reports whether the text component and its style are valid. An empty Asset draws nothing; a set one requires a positive size and a single line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL