Documentation
¶
Overview ¶
Package animation provides state-based sprite animation and playback signals.
Index ¶
Constants ¶
const SystemName = "animation"
SystemName is the registered name of Animate.
Variables ¶
This section is empty.
Functions ¶
func Animate ¶ added in v0.4.0
Animate advances Animator components and emits playback signals.
Games created by github.com/Leonard-Atorough/castrum.New register it in core.PhaseFixed. When an animator exists, the world must provide Sets and signal.Hub resources.
Types ¶
type Animator ¶ added in v0.4.0
type Animator struct {
// Set is the key of the animation set.
Set string `json:"set"`
// State is the desired state name.
State string `json:"state"`
// Speed is the playback multiplier; zero means normal speed.
Speed float64 `json:"speed,omitempty"`
// Paused controls whether playback is paused.
Paused bool `json:"paused,omitempty"`
// Style controls the appearance of the animation.
Style sprite.Style `json:"style,omitempty"`
// contains filtered or unexported fields
}
Animator is a per-entity animation component with serializable desired state.
func NewAnimator ¶ added in v0.4.0
NewAnimator returns an Animator with the given set and desired state. It returns an error if either name is empty.
func (Animator) Current ¶ added in v0.4.0
Current returns the state actually playing, which may differ from State. It returns an empty string before playback starts.
func (Animator) Finished ¶ added in v0.4.0
Finished reports whether a LoopOnce state has completed and is holding its final frame. It remains true until Animate starts another state.
func (Animator) Frames ¶ added in v0.4.0
func (a Animator) Frames(sets Sets) ([]WeightedFrame, error)
Frames returns the current state's weighted layers for drawing. It returns nil without error before playback starts.
During a blend, outgoing layers precede incoming layers. It returns an error if the Animator is invalid or a required set or state is missing, or if the blend easing name is unknown.
type Completed ¶ added in v0.3.0
type Completed struct {
// Entity is the entity whose primary track reached a boundary.
Entity core.Entity
// Tick is the fixed tick of the completion.
Tick uint64
// State is the name of the state whose primary track reached a boundary.
State string
// Loops is the number of forward wraps for [Loop], or 1 for other modes.
Loops uint64
}
Completed is emitted by Animate when a state's primary track reaches a boundary. It emits one signal per animator per tick, even if a looping state wraps multiple times in one tick.
type LoopMode ¶
type LoopMode int
LoopMode controls what happens after an animation reaches its final frame.
type Set ¶ added in v0.4.0
type Set struct {
// Name is the set's name.
Name string `json:"name"`
// States maps state names to states.
States map[string]State `json:"states"`
}
Set groups named animation states.
type Sets ¶ added in v0.4.0
type Sets struct {
// contains filtered or unexported fields
}
Sets is a named collection of animation sets, intended as a world resource.
func NewSets ¶ added in v0.4.0
NewSets returns a validated Sets containing deep copies of the input sets. It returns an error if the collection is empty or any set or key is invalid.
func (Sets) Get ¶ added in v0.4.0
Get returns the named set and whether it exists. The returned set's maps and slices share storage with the collection.
func (Sets) MarshalJSON ¶ added in v0.4.0
MarshalJSON encodes the collection as a JSON object keyed by set name.
func (*Sets) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON decodes a JSON object into the collection without validating it.
type Started ¶ added in v0.4.0
type Started struct {
// Entity is the entity whose state started.
Entity core.Entity
// Tick is the fixed tick of the start.
Tick uint64
// State is the name of the state that started.
State string
}
Started is emitted by Animate when an Animator begins playing a state.
type State ¶ added in v0.4.0
type State struct {
// Name is the state's name.
Name string `json:"name"`
// Tracks are the layers played in the state.
Tracks []Track `json:"tracks"`
// Loop controls whether the state repeats.
Loop LoopMode `json:"loop,omitempty"`
// EnterBlend is the duration in seconds of the transition into the state.
EnterBlend float64 `json:"enterBlend,omitempty"`
// BlendEase names the easing function for the enter transition. Empty
// defaults to linear; unknown names are rejected by [State.Validate].
BlendEase string `json:"blendEase,omitempty"`
// Next is the state to enter when the primary track reaches a boundary.
// An empty name disables the automatic transition.
Next string `json:"next,omitempty"`
}
State defines an animation state and its tracks.
type Track ¶ added in v0.4.0
type Track struct {
// Name is the track's name.
Name string `json:"name"`
// Source is the sheet document ID.
Source asset.ID `json:"source"`
// Frames are the sheet region names in playback order.
Frames []string `json:"frames"`
// FPS is the playback rate in frames per second.
FPS float64 `json:"fps"`
}
Track is one layer of a State: a named sequence of sheet regions at a fixed rate. Tracks in one state play together.
type WeightedFrame ¶ added in v0.4.0
type WeightedFrame struct {
// Track is the name of the track.
Track string
// Source is the sheet containing the region.
Source asset.SheetRef
// Region is the name of the sheet region.
Region string
// Weight is the layer's blend weight.
Weight float64
}
WeightedFrame is one drawable layer: a track's current region and its blend weight.