Documentation
¶
Overview ¶
+game:group:name=gfx
Package gfx holds the plain-data side of rendering: value types (Vec2, Rect, Color), asset handles and the components that describe how an entity looks. It imports only the stdlib-only asset package, neither ecs nor Ebiten, so components stay serializable through the Game Object Definition and tools never have to compile an engine. Package render draws them; package extract connects the two.
Index ¶
- Variables
- func Override[T any](v T) *T
- type AnimatedVisual
- type AnimatedVisualView
- func (v AnimatedVisualView) Each() iter.Seq2[ecs.Entity, AnimatedVisual]
- func (v AnimatedVisualView) Get(e ecs.Entity) AnimatedVisual
- func (v AnimatedVisualView) Has(e ecs.Entity) bool
- func (v AnimatedVisualView) NewEntity(obj AnimatedVisual) ecs.Entity
- func (v AnimatedVisualView) Remove(e ecs.Entity)
- func (v AnimatedVisualView) Set(e ecs.Entity, obj AnimatedVisual)
- type Animator
- type Blend
- type Box
- type BoxKind
- type ClipHandle
- type Color
- type DebugOutline
- type DebugOutlines
- type DebugShape
- type DialogueHandle
- type EffectHandle
- type EmitShape
- type FontHandle
- type IRect
- type Insets
- type Label
- type MusicHandle
- type NineSlice
- type Panel
- type PanelView
- type ParticleSource
- type ParticleSourceView
- func (v ParticleSourceView) Each() iter.Seq2[ecs.Entity, ParticleSource]
- func (v ParticleSourceView) Get(e ecs.Entity) ParticleSource
- func (v ParticleSourceView) Has(e ecs.Entity) bool
- func (v ParticleSourceView) NewEntity(obj ParticleSource) ecs.Entity
- func (v ParticleSourceView) Remove(e ecs.Entity)
- func (v ParticleSourceView) Set(e ecs.Entity, obj ParticleSource)
- type Particles
- type PlayerSlot
- type Pose
- type PrefabHandle
- type Rect
- type ScreenNineSlice
- type ScreenSprite
- type ScriptHandle
- type ShaderHandle
- type ShapeKind
- type SoundEmitter
- type SoundHandle
- type SoundSource
- type SoundSourceView
- func (v SoundSourceView) Each() iter.Seq2[ecs.Entity, SoundSource]
- func (v SoundSourceView) Get(e ecs.Entity) SoundSource
- func (v SoundSourceView) Has(e ecs.Entity) bool
- func (v SoundSourceView) NewEntity(obj SoundSource) ecs.Entity
- func (v SoundSourceView) Remove(e ecs.Entity)
- func (v SoundSourceView) Set(e ecs.Entity, obj SoundSource)
- type Sprite
- type SpriteHandle
- type Text
- type TextView
- type Time
- type Transform
- type Unscaled
- type Vec2
- type Visual
- type VisualView
- type VoiceHandle
Constants ¶
This section is empty.
Variables ¶
var ( CID_Animator = ecs.RegisterComp[Animator]() CID_Label = ecs.RegisterComp[Label]() CID_NineSlice = ecs.RegisterComp[NineSlice]() CID_Particles = ecs.RegisterComp[Particles]() CID_PlayerSlot = ecs.RegisterComp[PlayerSlot]() CID_SoundEmitter = ecs.RegisterComp[SoundEmitter]() CID_Sprite = ecs.RegisterComp[Sprite]() CID_Transform = ecs.RegisterComp[Transform]() CID_Unscaled = ecs.RegisterComp[Unscaled]() )
Functions ¶
Types ¶
type AnimatedVisual ¶
type AnimatedVisual struct {
// The positioned sprite.
// +game:embed
Visual
// Which clip plays and how fast.
// +game:component
Animator *Animator
}
AnimatedVisual is a Visual that plays animation clips: the Game Object of an animated sprite. Animator stays a standalone component, so plain Visual objects (and their serialized data) are unchanged. +game:object
type AnimatedVisualView ¶
type AnimatedVisualView struct {
// contains filtered or unexported fields
}
AnimatedVisualView is a thin handle over AnimatedVisual entities, bound to one World. It holds no entity state of its own.
func NewAnimatedVisualView ¶
func NewAnimatedVisualView(world *ecs.World) AnimatedVisualView
NewAnimatedVisualView returns a AnimatedVisualView bound to world. Create it once and keep it; copies share the same underlying state.
func (AnimatedVisualView) Each ¶
func (v AnimatedVisualView) Each() iter.Seq2[ecs.Entity, AnimatedVisual]
Each yields every entity that has all required components of AnimatedVisual, regardless of how it was created. Optional fields are always resolved, so Each yields the same AnimatedVisual that Get would return for the same entity.
Panics with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
func (AnimatedVisualView) Get ¶
func (v AnimatedVisualView) Get(e ecs.Entity) AnimatedVisual
Get returns a AnimatedVisual whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
func (AnimatedVisualView) Has ¶
func (v AnimatedVisualView) Has(e ecs.Entity) bool
Has reports whether e has every required component of AnimatedVisual, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
func (AnimatedVisualView) NewEntity ¶
func (v AnimatedVisualView) NewEntity(obj AnimatedVisual) ecs.Entity
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
func (AnimatedVisualView) Remove ¶
func (v AnimatedVisualView) Remove(e ecs.Entity)
Remove removes all of AnimatedVisual's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
func (AnimatedVisualView) Set ¶
func (v AnimatedVisualView) Set(e ecs.Entity, obj AnimatedVisual)
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of AnimatedVisual are left untouched.
Panics with "ecs: not bound to a world" if AnimatedVisualView is the zero value.
type Animator ¶
type Animator struct {
// Clip selects the clip. The zero handle, and a clip that is not loaded
// yet, leave the Sprite untouched.
//
// +game:asset:kind=clip
Clip ClipHandle `json:"-"`
// Time is how long the clip has played, scaled by Speed.
//
// +game:runtime
Time time.Duration `json:"-"`
// Frame is the index of the current frame in the clip, written by the
// system so that gameplay can react to it.
//
// +game:runtime
Frame int32 `json:"-"`
// Speed scales the playback rate. Zero means 1; negative values are
// treated as 1 too, because the clip's direction comes from the clip. The
// editor starts a new Animator at 1.
//
// +game:default=1
Speed float32
// Done is set when a non-looping clip has reached its last frame. The
// system then stops advancing the entity.
//
// +game:runtime
Done bool `json:"-"`
}
Animator plays an animation clip on the entity's Sprite: the anim package's AnimationSystem advances Time and writes Sprite.ID each tick.
Animator is a standalone Game Object component; objects opt in by marking a field of this type as a component. Clip and Speed are authored data (Clip is an asset key such as "chars/hero.aseprite.json#run"); Time, Frame and Done are runtime state, in the schema but marked x-runtime, so they are never serialized.
Restart a clip by setting Clip to the new handle and zeroing Time, Frame and Done.
+game:component
type Blend ¶
type Blend uint8
Blend selects how a drawable is composited onto what is below it. It mirrors render.Blend value for value (gfx cannot import render); extract systems convert with render.Blend(b).
+game:enum
const ( // BlendNormal draws the source over what is below (alpha blending). BlendNormal Blend = iota // BlendAdditive adds the source color to what is below: glows, fire, // sparks. BlendAdditive // BlendMultiply multiplies what is below by the source color: white // keeps it, black darkens it to black. BlendMultiply // BlendScreen brightens like BlendAdditive but never exceeds white: // soft glows, light shafts, flashes. BlendScreen // BlendSubtract subtracts the source color from what is below: // darkening tints, negative light. BlendSubtract // BlendLighten keeps the brighter of source and destination per // channel: overlapping glows that do not add up. BlendLighten // BlendErase removes what is below by the source's alpha. Use it inside // a layer group to cut holes (fog of war, flashlight masks). BlendErase )
Blend modes.
type Box ¶
type Box struct {
// Kind says whether the box deals or receives hits.
Kind BoxKind
// ID names the box for gameplay ("slash-down"); it may be empty. Boxes of
// one attack usually share an ID so that a hit counts once per swing.
ID string
// Rect is the box relative to the pivot.
Rect IRect
}
Box is a hit or hurt box of an animation frame. Rect is relative to the sprite's pivot (the pivot is (0, 0)), y down, in pixels of the art. Boxes are plain data: the engine draws them on request but does no collision detection.
func (Box) World ¶
World returns the box in world units for an entity at t that is drawn mirrored by flipX/flipY (Sprite.FlipX/FlipY). It applies the same rules as the renderer: a flip mirrors around the pivot (x' = -(x + w)), then the box is scaled by t.Scale (the zero Scale means (1, 1)) and moved to t.Pos. Rotation is ignored, so the result is an axis-aligned rect even for a rotated entity. It does not allocate.
type BoxKind ¶
type BoxKind uint8
BoxKind says what a Box is for.
type ClipHandle ¶
ClipHandle refers to an anim.Clip. Load one with anim.LoadClip.
type Color ¶
type Color uint32
Color is a packed 0xRRGGBBAA color, non-premultiplied. In memory it is a plain uint32; in files it is the string "#rrggbbaa" (see Color.MarshalText), schema format "color".
The zero value means "no tint" (opaque white), not transparent black, so that a zero-valued component draws normally. Its text is "#00000000". A fully transparent color is any value with a zero alpha byte but other bits set, such as RGBA(255, 255, 255, 0), "#ffffff00".
func ParseColor ¶
ParseColor reads "#rrggbbaa", or "#rrggbb" for an opaque color, in any case. "#00000000" is the zero Color, which draws white; write a transparent color with other bits set, such as "#ffffff00". The error names s.
func (Color) Floats ¶
Floats returns the channels as non-premultiplied values in [0,1]. The zero Color is returned as opaque white.
func (Color) MarshalText ¶
MarshalText writes c as "#rrggbbaa" in lowercase. The zero Color (no tint, drawn white) is "#00000000", so it reads back as zero.
func (*Color) UnmarshalText ¶
UnmarshalText reads a color written by Color.MarshalText or by hand: "#rrggbbaa", or "#rrggbb" for an opaque color, in any case. See ParseColor.
type DebugOutline ¶
type DebugOutline struct {
// Circle selects a circle of Radius around Center; otherwise the
// outline is the rectangle Bounds.
Circle bool
// Bounds is the rectangle, in world units.
Bounds Rect
// Center and Radius describe the circle, in world units.
Center Vec2
Radius float32
// Color is the outline color.
Color Color
}
DebugOutline is one outline the debug overlay draws in world space: the bounds of a collider, or a circle.
type DebugOutlines ¶
type DebugOutlines struct {
// Outlines yields the outlines of the last run. The yielded values are
// copies. It may be nil.
Outlines iter.Seq[DebugOutline]
}
DebugOutlines is a World resource: a source of outlines for the debug overlay (extract.DebugExtract), set by the package that owns the shapes (collision sets it for its Space). It lets the overlay draw shapes it knows nothing about, so extract needs no import of them.
type DebugShape ¶
type DebugShape struct {
// Kind selects the primitive.
Kind ShapeKind
// Size is the width/height of a rect, the radius (in X) of a circle, or
// the end offset of a line.
Size Vec2
// Color is the line color. Zero means white.
Color Color
}
DebugShape draws an outline-style primitive at the entity's Transform in world space, for collider and path visualization.
type DialogueHandle ¶
DialogueHandle refers to a speech.Dialogue, a *.dialogue.json file. Load one with speech.LoadDialogue.
type EffectHandle ¶
EffectHandle refers to a particles.Effect, a particle effect loaded from an *.fx.json file. Load one with particles.LoadEffect.
type EmitShape ¶
type EmitShape uint8
EmitShape selects the area a particle emitter spawns particles in.
+game:enum
type FontHandle ¶
FontHandle refers to a render.Font. Load one with render.LoadFont.
type IRect ¶
type IRect struct {
X, Y, W, H int32
}
IRect is an integer rectangle in pixels: X, Y is the top-left corner (y down), W and H the size. Animation boxes use it because they are authored on the pixel grid of the art.
type Insets ¶
type Insets struct {
Left, Top, Right, Bottom uint16
}
Insets are the widths of the four borders of a nine-slice image, in pixels of the source image.
type Label ¶
type Label struct {
// Text is the string to draw.
Text string
// Font selects the font face. In the Game Object schema it is an asset key
// ("fonts/ui.json"); the handle is runtime-only (json:"-").
//
// +game:asset:kind=font
Font FontHandle `json:"-"`
// Layer is the draw order, as for Sprite.
Layer int16
// Color is the text color. Zero means white.
Color Color
// Shader draws the text through a Kage shader. The shader gets the whole
// text as one image, with a transparent margin of 4 pixels around it for
// outlines and glows, and Color as its color argument. The zero handle,
// and a shader that is still loading or failed, draw the text normally.
// A shaded text is a draw call of its own. In the Game Object schema it
// is an asset key ("fx/outline.kage"); the handle is runtime-only
// (json:"-").
//
// +game:asset:kind=shader
Shader ShaderHandle `json:"-"`
// Params are passed to Shader as its "Params" vec4 uniform; their meaning
// is up to the shader.
Params [4]float32 `json:",omitzero"`
}
Label draws text at the entity's Transform in screen space.
type MusicHandle ¶
MusicHandle refers to a sound.Music, a track streamed while it plays. Load one with sound.LoadMusic.
type NineSlice ¶
type NineSlice struct {
// ID selects the image. In the Game Object schema it is an asset key
// ("ui/panel.png"); the handle is runtime-only (json:"-").
//
// +game:asset:kind=sprite
ID SpriteHandle `json:"-"`
// Insets are the border widths in source pixels.
Insets Insets
// Size is the drawn size in pixels before Transform.Scale. Zero means the
// image's own size.
Size Vec2
// Layer is the draw order, as for Sprite.
Layer int16
// Origin is the pivot as a fraction of Size. The zero Origin is the
// top-left corner.
Origin Vec2
// Tint multiplies the image color. Zero means no tint.
Tint Color
// Blend is how the panel is composited onto what is below it. Zero is
// BlendNormal.
Blend Blend
// Tile repeats the edges and the center at the image's pixel size instead
// of stretching them. The last repeat in a row or column is cropped.
Tile bool
// Shader draws the panel through a Kage shader. The shader gets the
// whole panel at its Size as one image, with a transparent margin of 4
// pixels around it for outlines and glows, and Tint as its color
// argument. The zero handle, and a shader that is still loading or
// failed, draw the panel normally. A shaded panel is a draw call of its
// own. In the Game Object schema it is an asset key ("fx/outline.kage");
// the handle is runtime-only (json:"-").
//
// +game:asset:kind=shader
Shader ShaderHandle `json:"-"`
// Params are passed to Shader as its "Params" vec4 uniform; their meaning
// is up to the shader.
Params [4]float32 `json:",omitzero"`
// Hidden skips the panel. It is a field and not a tag so that toggling it
// does not move the entity between archetypes.
Hidden bool
}
NineSlice draws an image at any size without distorting its border: the four corners keep their pixel size, the four edges stretch along one axis and the center stretches along both (or repeats, with Tile). The same 24x24 panel image then serves a dialog, a button and a health-bar frame. Resize a panel by writing Size; that never moves the entity between archetypes.
Zero values draw normally: a zero Size is the image's own size, a zero Origin the top-left corner, a zero Tint white and zero Insets stretch the whole image. Transform.Scale multiplies everything, corners included, and Transform.Rot rotates the panel around its origin. Insets that exceed the image are clamped; when Size is smaller than the borders together, the borders shrink in proportion and the center is empty.
Insets are measured on the frame as stored: use untrimmed art for atlas frames.
+game:component
type Panel ¶
type Panel struct {
// Where the panel is.
// +game:component
Transform *Transform
// The image, its insets and size.
// +game:component
NineSlice *NineSlice
}
Panel is a NineSlice placed by a Transform: the Game Object of a UI panel or frame that resizes without distorting its border. +game:object
type PanelView ¶
type PanelView struct {
// contains filtered or unexported fields
}
PanelView is a thin handle over Panel entities, bound to one World. It holds no entity state of its own.
func NewPanelView ¶
NewPanelView returns a PanelView bound to world. Create it once and keep it; copies share the same underlying state.
func (PanelView) Each ¶
Each yields every entity that has all required components of Panel, regardless of how it was created. Optional fields are always resolved, so Each yields the same Panel that Get would return for the same entity.
Panics with "ecs: not bound to a world" if PanelView is the zero value.
func (PanelView) Get ¶
Get returns a Panel whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if PanelView is the zero value.
func (PanelView) Has ¶
Has reports whether e has every required component of Panel, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if PanelView is the zero value.
func (PanelView) NewEntity ¶
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if PanelView is the zero value.
func (PanelView) Remove ¶
Remove removes all of Panel's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if PanelView is the zero value.
func (PanelView) Set ¶
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of Panel are left untouched.
Panics with "ecs: not bound to a world" if PanelView is the zero value.
type ParticleSource ¶
type ParticleSource struct {
// Where the particles spawn.
// +game:component
Transform *Transform
// The effect to play.
// +game:component
Particles *Particles
}
ParticleSource is a particle effect placed in the world: dust, embers, sparks. Particles stays a standalone component too, so other objects and prefabs can carry one. +game:object
type ParticleSourceView ¶
type ParticleSourceView struct {
// contains filtered or unexported fields
}
ParticleSourceView is a thin handle over ParticleSource entities, bound to one World. It holds no entity state of its own.
func NewParticleSourceView ¶
func NewParticleSourceView(world *ecs.World) ParticleSourceView
NewParticleSourceView returns a ParticleSourceView bound to world. Create it once and keep it; copies share the same underlying state.
func (ParticleSourceView) Each ¶
func (v ParticleSourceView) Each() iter.Seq2[ecs.Entity, ParticleSource]
Each yields every entity that has all required components of ParticleSource, regardless of how it was created. Optional fields are always resolved, so Each yields the same ParticleSource that Get would return for the same entity.
Panics with "ecs: not bound to a world" if ParticleSourceView is the zero value.
func (ParticleSourceView) Get ¶
func (v ParticleSourceView) Get(e ecs.Entity) ParticleSource
Get returns a ParticleSource whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if ParticleSourceView is the zero value.
func (ParticleSourceView) Has ¶
func (v ParticleSourceView) Has(e ecs.Entity) bool
Has reports whether e has every required component of ParticleSource, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if ParticleSourceView is the zero value.
func (ParticleSourceView) NewEntity ¶
func (v ParticleSourceView) NewEntity(obj ParticleSource) ecs.Entity
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if ParticleSourceView is the zero value.
func (ParticleSourceView) Remove ¶
func (v ParticleSourceView) Remove(e ecs.Entity)
Remove removes all of ParticleSource's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if ParticleSourceView is the zero value.
func (ParticleSourceView) Set ¶
func (v ParticleSourceView) Set(e ecs.Entity, obj ParticleSource)
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of ParticleSource are left untouched.
Panics with "ecs: not bound to a world" if ParticleSourceView is the zero value.
type Particles ¶
type Particles struct {
// Effect is the particle effect to play. The zero handle plays nothing.
//
// +game:asset:kind=effect
Effect EffectHandle `json:"-"`
// Layer is the draw order, as for Sprite. Give additive particles their
// own layer so they batch.
Layer int16
// Stop stops spawning; live particles finish their life.
Stop bool
// Seed seeds the random numbers. Zero derives it from the entity.
Seed uint32
// Sprite overrides the effect's particle image. The zero handle uses the
// effect's own; an instance cannot override back to the placeholder.
//
// +game:asset:kind=sprite
Sprite SpriteHandle `json:"-"`
// Shader overrides the effect's shader. The zero handle uses the
// effect's own; an instance cannot override to no shader.
//
// +game:asset:kind=shader
Shader ShaderHandle `json:"-"`
// Params override the shader's Params vec4.
Params *[4]float32 `json:",omitzero"`
// Blend overrides the blend mode.
Blend *Blend `json:",omitzero"`
// Color overrides the tint at birth.
//
// +game:editor:color=true
Color *Color `json:",omitzero"`
// EndColor overrides the tint at death.
//
// +game:editor:color=true
EndColor *Color `json:",omitzero"`
// Scale overrides the particle size at birth.
Scale *float32 `json:",omitzero"`
// EndScale overrides the size at death.
EndScale *float32 `json:",omitzero"`
// FadeIn overrides the fraction of the life over which alpha ramps up.
//
// +game:editor:min=0,max=1,step=0.05
FadeIn *float32 `json:",omitzero"`
// FadeOut overrides the fraction of the life over which alpha ramps down.
//
// +game:editor:min=0,max=1,step=0.05
FadeOut *float32 `json:",omitzero"`
// Rate overrides the particles spawned per second.
//
// +game:editor:unit=/s
Rate *float32 `json:",omitzero"`
// Burst overrides the particles spawned at the start of each cycle.
Burst *uint16 `json:",omitzero"`
// Duration overrides the cycle length in seconds; zero is forever.
//
// +game:editor:unit=s
Duration *float32 `json:",omitzero"`
// Loop overrides whether the cycle restarts after Duration.
Loop *bool `json:",omitzero"`
// Max overrides the pool capacity; zero means 256.
Max *uint16 `json:",omitzero"`
// Shape overrides the spawn area.
Shape *EmitShape `json:",omitzero"`
// ShapeSize overrides the spawn area's size.
ShapeSize *Vec2 `json:",omitzero"`
// LifeMin overrides the shortest lifetime in seconds.
//
// +game:editor:unit=s
LifeMin *float32 `json:",omitzero"`
// LifeMax overrides the longest lifetime in seconds.
//
// +game:editor:unit=s
LifeMax *float32 `json:",omitzero"`
// Angle overrides the emission direction.
//
// +game:editor:unit=deg,step=5
Angle *float32 `json:",omitzero"`
// Spread overrides the full cone width around Angle.
//
// +game:editor:unit=deg,step=5
Spread *float32 `json:",omitzero"`
// SpeedMin overrides the slowest initial speed in units/s.
//
// +game:editor:unit=u/s
SpeedMin *float32 `json:",omitzero"`
// SpeedMax overrides the fastest initial speed in units/s.
//
// +game:editor:unit=u/s
SpeedMax *float32 `json:",omitzero"`
// Gravity overrides the constant acceleration in units/s².
Gravity *Vec2 `json:",omitzero"`
// Drag overrides the slowdown factor per second.
Drag *float32 `json:",omitzero"`
// SpinMin overrides the slowest rotation speed.
//
// +game:editor:unit=deg,step=5
SpinMin *float32 `json:",omitzero"`
// SpinMax overrides the fastest rotation speed.
//
// +game:editor:unit=deg,step=5
SpinMax *float32 `json:",omitzero"`
// RandomRotation overrides whether particles start rotated at random.
RandomRotation *bool `json:",omitzero"`
// Local overrides whether particles move with the emitter.
Local *bool `json:",omitzero"`
// Pool identifies the particle pool in the system; zero means none.
//
// +game:runtime
Pool uint32 `json:"-"`
// Time is how long the current cycle of the effect's first emitter has
// run, in seconds. Zeroing it restarts the cycle of every emitter.
//
// +game:runtime
Time float32 `json:"-"`
// Live is the number of live particles of all emitters, written by the
// system for gameplay and the inspector.
//
// +game:runtime
Live uint16 `json:"-"`
// Done is set when every emitter of a non-looping effect has finished
// and its last particle died.
//
// +game:runtime
Done bool `json:"-"`
}
Particles plays a particle effect at the entity's Transform: the particles package's System simulates it every tick and its Extract draws the particles as batched sprites. The effect itself (image, colors, rate, lifetimes, speeds, shape, gravity) is an asset, an *.fx.json file; the component holds its handle, as Animator holds a clip, plus the few things that differ per placed instance. Particles are not entities; they live in pools owned by the system, so thousands of them cost no archetype churn.
The Transform's Rot turns the emission direction, the spawn shape and the particles' start rotation; its Scale stretches the spawn shape and the particle size. Both apply when a particle spawns, not to live particles. An effect that is still loading spawns nothing; editing its file restarts the particles of every entity that plays it.
An effect may hold several emitters (up to fxfile.MaxEmitters, in package particles/fxfile); they play together, and Layer, Stop, Seed and the overrides below apply to all of them.
Randomness is deterministic: the same Seed (or entity) and inputs give the same particles. Pool, Time, Live and Done are runtime state, never serialized. Restart a finished effect by zeroing Time and Done.
+game:component
type PlayerSlot ¶
type PlayerSlot struct {
// Player is the player index, 0..input.MaxPlayers-1.
Player uint8
}
PlayerSlot says which input player controls the entity: the index of an input.Player (Router.Player). Game systems read the player's State through it, so the same controller system drives every player's character.
+game:component
type Pose ¶
type Pose struct {
Pos Vec2
Rot float32
Scale Vec2
// Set reports whether the pose was recorded. Readers treat an unset pose
// as the current one.
Set bool
}
Pose is where a Transform was at one tick: its position, rotation and scale. The zero Pose (Set false) means "none".
type PrefabHandle ¶
PrefabHandle refers to a prefab.Prefab. Load one with prefab.Load; it is the same type as prefab.Handle.
type Rect ¶
Rect is an axis-aligned rectangle from Min (inclusive) to Max (exclusive). It is an alias of xmath.Rect, which holds its methods (Contains, Grow, ...).
type ScreenNineSlice ¶
type ScreenNineSlice struct {
// NineSlice is the image and its drawing options.
NineSlice NineSlice
}
ScreenNineSlice is a NineSlice drawn in screen space (HUD, UI): Transform.Pos is in logical screen pixels and the camera is ignored.
type ScreenSprite ¶
type ScreenSprite struct {
// Sprite is the image and its drawing options.
Sprite Sprite
}
ScreenSprite is a Sprite drawn in screen space (HUD, UI): Transform.Pos is in logical screen pixels and the camera is ignored.
type ScriptHandle ¶
ScriptHandle refers to a script.Script, a compiled *.gs file. Load one with script.Load.
type ShaderHandle ¶
ShaderHandle refers to a render.Shader. Load one with render.LoadShader. The zero handle means "no shader".
type SoundEmitter ¶
type SoundEmitter struct {
// Sound selects the effect. The zero handle plays nothing; a sound that
// is still loading starts when it is ready, a failed one sets Done.
//
// +game:asset:kind=sound
Sound SoundHandle `json:"-"`
// Volume scales the sound. Zero means 1 (full volume), like
// Animator.Speed; a negative value is silent. The editor starts a new
// emitter at 1.
//
// +game:default=1
Volume float32
// Bus is the mixer bus (a sound.Bus) whose volume applies. Zero is
// sound.BusSFX.
Bus uint8
// Loop repeats the sound while the emitter exists.
Loop bool
// Voice identifies the playing voice in the AudioSystem; zero means none.
//
// +game:runtime
Voice uint32 `json:"-"`
// Done is set when a one-shot sound has started (or the sound failed to
// load). The system then ignores the emitter.
//
// +game:runtime
Done bool `json:"-"`
}
SoundEmitter plays a sound at the entity: the sound package's AudioSystem starts it once the sound is loaded. A one-shot emitter starts once, sets Done, and plays to its end even if the entity is deleted; a looping one plays for as long as the entity has the component, and stops when the entity is deleted, the component removed or Done set. If the entity has a Transform, the sound is panned (and, with a listener range, attenuated) by its position relative to the sound.Listener.
Sound, Volume, Bus and Loop are authored data (Sound is an asset key such as "sfx/waterfall.ogg"); Voice and Done are runtime state, never serialized. Replay a one-shot emitter by zeroing Done.
+game:component
type SoundHandle ¶
SoundHandle refers to a sound.Sound, a short effect decoded to memory. Load one with sound.LoadSound.
type SoundSource ¶
type SoundSource struct {
// Where the sound is; it pans by this position.
// +game:component
Transform *Transform
// What plays and how loud.
// +game:component
SoundEmitter *SoundEmitter
}
SoundSource is a sound placed in the world: a waterfall loop, a one-shot stinger at a spot. SoundEmitter stays a standalone component too, so other objects can carry one. +game:object
type SoundSourceView ¶
type SoundSourceView struct {
// contains filtered or unexported fields
}
SoundSourceView is a thin handle over SoundSource entities, bound to one World. It holds no entity state of its own.
func NewSoundSourceView ¶
func NewSoundSourceView(world *ecs.World) SoundSourceView
NewSoundSourceView returns a SoundSourceView bound to world. Create it once and keep it; copies share the same underlying state.
func (SoundSourceView) Each ¶
func (v SoundSourceView) Each() iter.Seq2[ecs.Entity, SoundSource]
Each yields every entity that has all required components of SoundSource, regardless of how it was created. Optional fields are always resolved, so Each yields the same SoundSource that Get would return for the same entity.
Panics with "ecs: not bound to a world" if SoundSourceView is the zero value.
func (SoundSourceView) Get ¶
func (v SoundSourceView) Get(e ecs.Entity) SoundSource
Get returns a SoundSource whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if SoundSourceView is the zero value.
func (SoundSourceView) Has ¶
func (v SoundSourceView) Has(e ecs.Entity) bool
Has reports whether e has every required component of SoundSource, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if SoundSourceView is the zero value.
func (SoundSourceView) NewEntity ¶
func (v SoundSourceView) NewEntity(obj SoundSource) ecs.Entity
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if SoundSourceView is the zero value.
func (SoundSourceView) Remove ¶
func (v SoundSourceView) Remove(e ecs.Entity)
Remove removes all of SoundSource's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if SoundSourceView is the zero value.
func (SoundSourceView) Set ¶
func (v SoundSourceView) Set(e ecs.Entity, obj SoundSource)
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of SoundSource are left untouched.
Panics with "ecs: not bound to a world" if SoundSourceView is the zero value.
type Sprite ¶
type Sprite struct {
// ID selects the image. Animation systems change it per frame. The zero
// handle draws the placeholder. In the Game Object schema it is an asset
// key ("chars/hero.aseprite.json#idle_0"); the handle itself is
// runtime-only (json:"-"), and the resolver package converts the two.
//
// +game:asset:kind=sprite
ID SpriteHandle `json:"-"`
// Layer is the draw order: higher layers draw on top.
Layer int16
// Origin is the pivot as a fraction of the sprite size: (0.5,0.5) is the
// center. The zero Origin means the sprite's own default pivot, so
// top-left needs a tiny non-zero value such as (0.0001, 0.0001).
Origin Vec2
// FlipX mirrors the sprite horizontally.
FlipX bool
// FlipY mirrors the sprite vertically.
FlipY bool
// Tint multiplies the sprite's color. Zero means no tint.
Tint Color
// Blend is how the sprite is composited onto what is below it. The zero
// value is BlendNormal. Give blended sprites a layer of their own so they
// batch.
Blend Blend
// Shader draws the sprite through a Kage shader (hit flash, outline,
// palette swap). The zero handle, and a shader that is still loading or
// failed, draw the sprite normally. In the Game Object schema it is an
// asset key ("fx/flash.kage"); the handle is runtime-only (json:"-").
//
// +game:asset:kind=shader
Shader ShaderHandle `json:"-"`
// Params are passed to Shader as its "Params" vec4 uniform; their meaning
// is up to the shader. Animate them instead of swapping shaders: changing
// a field does not move the entity between archetypes.
Params [4]float32 `json:",omitzero"`
// Aux is a second image for Shader (a noise texture for a dissolve, a
// mask, a palette), which the shader reads as imageSrc1; without Shader
// it is ignored. The zero handle, and a sprite that is loading or
// failed, give the shader no image (transparent pixels). In the Game
// Object schema it is an asset key ("fx/noise.png"); the handle is
// runtime-only (json:"-").
//
// +game:asset:kind=sprite
Aux SpriteHandle `json:"-"`
// Hidden skips the sprite. It is a field and not a tag so that toggling
// it does not move the entity between archetypes.
Hidden bool
}
Sprite draws an image at the entity's Transform.
type SpriteHandle ¶
SpriteHandle refers to a render.Sprite. Load one with render.LoadSprite.
type Text ¶
type Text struct {
// Where the text is.
// +game:component
Transform *Transform
// The string and how it is drawn.
// +game:component
Label *Label
}
Text is a Label placed by a Transform: the Game Object of a text entity. The Label is drawn in screen space, so Transform.Pos is in logical pixels. +game:object
type TextView ¶
type TextView struct {
// contains filtered or unexported fields
}
TextView is a thin handle over Text entities, bound to one World. It holds no entity state of its own.
func NewTextView ¶
NewTextView returns a TextView bound to world. Create it once and keep it; copies share the same underlying state.
func (TextView) Each ¶
Each yields every entity that has all required components of Text, regardless of how it was created. Optional fields are always resolved, so Each yields the same Text that Get would return for the same entity.
Panics with "ecs: not bound to a world" if TextView is the zero value.
func (TextView) Get ¶
Get returns a Text whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if TextView is the zero value.
func (TextView) Has ¶
Has reports whether e has every required component of Text, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if TextView is the zero value.
func (TextView) NewEntity ¶
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if TextView is the zero value.
func (TextView) Remove ¶
Remove removes all of Text's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if TextView is the zero value.
func (TextView) Set ¶
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of Text are left untouched.
Panics with "ecs: not bound to a world" if TextView is the zero value.
type Time ¶
type Time struct {
// Delta is the scaled length of this tick: Unscaled times Scale.
Delta time.Duration
// Unscaled is the fixed length of a tick, 1s/TPS.
Unscaled time.Duration
// Elapsed is the sum of Delta over all ticks so far, this one included.
// The shader Time uniform follows it.
Elapsed time.Duration
// UnscaledElapsed is the sum of Unscaled over all ticks so far, this one
// included.
UnscaledElapsed time.Duration
// Scale is the effective time scale of this tick: the game's scale,
// times 0 while a scene that pauses time is on the stack, times the
// tool's scale. 0 means time stands still.
Scale float32
}
Time is the game clock of one tick, a World resource that the game.Engine writes before every tick and systems only read. It lives in gfx, the plain-data package, so the anim, particle, tween and camera packages can read it without importing the engine.
Delta is the scaled tick: the fixed tick (Unscaled) times Scale. It is what system.Context.Time.Delta holds in every stage, so movement, physics, animations, particles and tweens slow down and stop with the scale. Unscaled is for what must keep real time: the pause menu's own systems, entities with the Unscaled marker, room transition fades and audio.
type Transform ¶
type Transform struct {
// Pos is the position in world units at the current tick.
Pos Vec2
// Rot is the rotation in radians, clockwise on screen.
//
// +game:editor:unit=deg,step=5
Rot float32
// Scale multiplies the sprite size. Zero means (1, 1); the editor starts a
// new Transform at (1, 1).
//
// +game:default:X=1,Y=1
Scale Vec2
// Prev is the pose at the start of the tick. The
// extract.SnapshotTransforms system writes it (see Snapshot), and the
// renderer blends Prev.Pos to Pos so that 60 TPS looks smooth on faster
// displays (rotation and scale are recorded but not blended). The zero Prev means "no previous pose": the entity is
// drawn at its current pose for the rest of the tick. That is what a
// new Transform has, whatever created it, and what Teleport sets, so
// neither streaks across the screen for a frame. It is runtime state,
// never in level or prefab files.
//
// +game:runtime
Prev Pose `json:"-"`
}
Transform places an entity in the world.
The zero Scale means (1, 1), so a zero-valued Transform is valid, and so is a new one with only Pos set: it is drawn at Pos from its first frame.
func (*Transform) PrevPose ¶
PrevPose returns the pose at the start of the tick: Prev when it is set, else the current pose (for an entity created or teleported during this tick). The result has Set true.
func (*Transform) Snapshot ¶
func (t *Transform) Snapshot()
Snapshot records the current pose in Prev. The engine calls it for every Transform at the start of each tick (extract.SnapshotTransforms).
type Unscaled ¶
type Unscaled struct{}
Unscaled marks an entity that keeps real time while the game clock is slowed down or stopped (Time.Scale): its sprite clip (Animator) and its particles advance by Time.Unscaled instead of the scaled delta. Put it on the entities of a pause menu that must keep moving while time stands. It has no fields; the systems iterate marked entities in their own views, so it costs nothing per entity.
+game:component
type Vec2 ¶
Vec2 is a 2D vector in world units or pixels, depending on context. It is an alias of xmath.Vec2, which holds its methods (Add, Len, Lerp, ...), so components keep reading gfx.Vec2.
type Visual ¶
type Visual struct {
// Where the entity is.
// +game:component
Transform *Transform
// How the entity looks.
// +game:component
Sprite *Sprite
}
Visual is a positioned, drawn thing: the minimal Game Object of the renderer. Game-specific objects embed it with +game:embed. +game:object
type VisualView ¶
type VisualView struct {
// contains filtered or unexported fields
}
VisualView is a thin handle over Visual entities, bound to one World. It holds no entity state of its own.
func NewVisualView ¶
func NewVisualView(world *ecs.World) VisualView
NewVisualView returns a VisualView bound to world. Create it once and keep it; copies share the same underlying state.
func (VisualView) Each ¶
Each yields every entity that has all required components of Visual, regardless of how it was created. Optional fields are always resolved, so Each yields the same Visual that Get would return for the same entity.
Panics with "ecs: not bound to a world" if VisualView is the zero value.
func (VisualView) Get ¶
func (v VisualView) Get(e ecs.Entity) Visual
Get returns a Visual whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if VisualView is the zero value.
func (VisualView) Has ¶
func (v VisualView) Has(e ecs.Entity) bool
Has reports whether e has every required component of Visual, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if VisualView is the zero value.
func (VisualView) NewEntity ¶
func (v VisualView) NewEntity(obj Visual) ecs.Entity
NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.
Panics with "ecs: not bound to a world" if VisualView is the zero value.
func (VisualView) Remove ¶
func (v VisualView) Remove(e ecs.Entity)
Remove removes all of Visual's components (required and optional) that e has, in one archetype move. Other components stay.
Panics with "ecs: not bound to a world" if VisualView is the zero value.
func (VisualView) Set ¶
func (v VisualView) Set(e ecs.Entity, obj Visual)
Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of Visual are left untouched.
Panics with "ecs: not bound to a world" if VisualView is the zero value.
type VoiceHandle ¶
VoiceHandle refers to a speech.Voice, a *.voice.json file or a starter voice by name ("chirpy"). Load one with speech.LoadVoice.