Documentation
¶
Overview ¶
Package cutscene is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package cutscene plays video and in-engine timeline cutscenes in a game: in a scene or between scenes, skippable by a press, a key or back, and calling the game back when one ends or is skipped.
A cutscene is a Cutscene, written in YAML (Parse, Encode) in either version 1 (video only) or version 2 (video or timeline).
A video cutscene names a video source, mixer group, skip rules, picture fit and transparency; Player plays it in NSGo's own video view (core.Video) over the game's view while pausing the game's loop and suspending its mixer.
A timeline cutscene names a length and ordered camera, actor, dialogue (localization line IDs only), sound and music tracks, with clips carrying start, duration and easing. TimelinePlayer runs one deterministically on game.Loop's fixed steps against a sceneformat.BuiltScene or sceneformat.SceneDoc (with Seek for scrubbing), and Player.PlayTimeline wires the same skip input, lifecycle and between-scene transitions as video cutscenes.
Index ¶
- Constants
- Variables
- func Encode(c Cutscene) ([]byte, error)
- func IsBuiltinTrackKind(kind TrackKind) bool
- func RegisterTrackKind(spec TrackKindSpec) error
- func SceneIs3D(doc *sceneformat.SceneDoc) bool
- func SchemaCommentFor(version int) string
- func Validate(c Cutscene) error
- func ValidateTrackKindSpec(spec TrackKindSpec) error
- type Action
- type CaptionBridge
- type Clip
- type Cutscene
- type DialogueLine
- type Duration
- type Easing
- type Fit
- type Kind
- type Marker
- type Options
- type Player
- func (p *Player) Camera3D() (scene3d.Camera, bool)
- func (p *Player) CanSkip() bool
- func (p *Player) Dialogue() DialogueLine
- func (p *Player) Play(c Cutscene, done func(Result)) error
- func (p *Player) PlayTimeline(c Cutscene, target TimelineTarget, done func(Result)) (*TimelinePlayer, error)
- func (p *Player) Playing() bool
- func (p *Player) Scene(c Cutscene, done func(Result)) (*scene.Controller, error)
- func (p *Player) Skip() bool
- func (p *Player) Step(dt time.Duration)
- func (p *Player) Stop() bool
- func (p *Player) TimelineScene(c Cutscene, target TimelineTarget, done func(Result)) (*scene.Controller, error)
- func (p *Player) View() core.Node
- type Reason
- type Result
- type Scene3DTarget
- type SkipBehavior
- type TimelinePlayer
- func (p *TimelinePlayer) ActiveDialogue() DialogueLine
- func (p *TimelinePlayer) ActiveParticleEmitters() []*particles.Emitter
- func (p *TimelinePlayer) ActorPose3D(actorID string) (pos math3d.Vec3, yaw float32, ok bool)
- func (p *TimelinePlayer) ActorPosition(actorID string) (x, y float32, ok bool)
- func (p *TimelinePlayer) ActorState(actorID string) string
- func (p *TimelinePlayer) Camera3D() (scene3d.Camera, bool)
- func (p *TimelinePlayer) CameraState() (x, y, zoom float32, ok bool)
- func (p *TimelinePlayer) CanSkip() bool
- func (p *TimelinePlayer) Cutscene() Cutscene
- func (p *TimelinePlayer) Done() bool
- func (p *TimelinePlayer) DrawParticles(d *core.Drawing)
- func (p *TimelinePlayer) Length() time.Duration
- func (p *TimelinePlayer) ObjectActive(target string) (active bool, ok bool)
- func (p *TimelinePlayer) Pause()
- func (p *TimelinePlayer) Play()
- func (p *TimelinePlayer) Playing() bool
- func (p *TimelinePlayer) Reset()
- func (p *TimelinePlayer) Seek(at time.Duration)
- func (p *TimelinePlayer) Skip() bool
- func (p *TimelinePlayer) Stop() bool
- func (p *TimelinePlayer) Time() time.Duration
- func (p *TimelinePlayer) Update(dt time.Duration)
- func (p *TimelinePlayer) VirtualCamera() *camera.VirtualCamera
- type TimelineTarget
- type Track
- type TrackClipContext
- type TrackEvaluator
- type TrackEvaluatorFunc
- type TrackKind
- type TrackKindSpec
- type TrackResetter
Examples ¶
Constants ¶
const ( // MinVersion is the oldest cutscene file format version this package reads and writes (video cutscenes only). MinVersion = 1 // CurrentVersion is the newest cutscene file format version this package reads and writes. Version 2 adds timeline cutscenes alongside video cutscenes. CurrentVersion = 2 // MaxNestingDepth is the maximum nesting depth of control-track nested cutscenes allowed by TimelinePlayer and assetcheck. MaxNestingDepth = 8 // SchemaURL is where the JSON Schema of version 1 cutscene files is published. SchemaURL = "https://nsgo.games/schemas/cutscene.v1.json" // SchemaComment is a YAML language server comment pointing at SchemaURL. SchemaComment = "# yaml-language-server: $schema=" + SchemaURL // SchemaURLV2 is where the JSON Schema of version 2 cutscene files is published. SchemaURLV2 = "https://nsgo.games/schemas/cutscene.v2.json" // SchemaCommentV2 is the first line Encode writes for a version 2 cutscene file, pointing a YAML language server at SchemaURLV2. SchemaCommentV2 = "# yaml-language-server: $schema=" + SchemaURLV2 )
Variables ¶
var ErrReplaced = errors.New("cutscene: the stopped cutscene's done callback played another")
ErrReplaced is what Player.Play and Player.PlayTimeline return, playing nothing, when the done callback of the cutscene they stop plays another cutscene: that one plays instead.
Functions ¶
func Encode ¶
Encode checks c as Validate does and writes it as a cutscene file, with 2-space indents and its keys in a fixed order. Version 2 files begin with SchemaCommentV2; version 1 files are written unchanged without a header comment.
func IsBuiltinTrackKind ¶
IsBuiltinTrackKind reports whether kind is one of the built-in timeline track kinds.
func RegisterTrackKind ¶
func RegisterTrackKind(spec TrackKindSpec) error
RegisterTrackKind registers a game- or plugin-provided timeline track kind.
Built-in track kinds cannot be overridden, spec.Kind must be namespaced as "<namespace>.<name>" (such as "mygame.lights"), and registering the same kind twice fails.
func SceneIs3D ¶
func SceneIs3D(doc *sceneformat.SceneDoc) bool
SceneIs3D reports whether doc is a version 4+ scene using 3D features (environment, 3D camera, 3D light, mesh, model, gridMap, csg, path3d, decal, particles3d, sprite3d, label3d, probes, occluder, or 3D transform fields).
func SchemaCommentFor ¶
SchemaCommentFor returns the YAML language server schema comment for version: SchemaComment for version 1 and SchemaCommentV2 for version 2.
func Validate ¶
Validate checks c as a cutscene file: its version is in [MinVersion, CurrentVersion], version 1 uses only video fields, and the cutscene is valid for playback.
func ValidateTrackKindSpec ¶
func ValidateTrackKindSpec(spec TrackKindSpec) error
ValidateTrackKindSpec checks that spec declares a valid namespaced custom track kind and factory without registering it.
Types ¶
type Action ¶
type Action string
Action selects what a camera or actor clip does.
const ( // ActionHold holds the 2D camera on a target object or fixed coordinates. ActionHold Action = "hold" // ActionPan pans the 2D camera smoothly to a target object or fixed coordinates. ActionPan Action = "pan" // ActionFollow continuously tracks a target object with the 2D camera. ActionFollow Action = "follow" // ActionShot cuts the 3D camera to a fixed pose (pos plus lookAt, target or euler degrees, with optional fov). ActionShot Action = "shot" // ActionMove eases the 3D camera between two poses (fromPos/toPos, fromLookAt/toLookAt, fromEuler/toEuler or target, and optional fromFov/fov). ActionMove Action = "move" // ActionOrbit circles the 3D camera around a target object or lookAt point. ActionOrbit Action = "orbit" // ActionDolly moves the 3D camera along a Path3D object while looking at a target object, lookAt point or the path tangent. ActionDolly Action = "dolly" // ActionUseCamera switches the 3D camera to a 3D camera object in the scene. ActionUseCamera Action = "useCamera" // ActionWalk moves a 2D actor between coordinates over the clip's duration. ActionWalk Action = "walk" // ActionState plays a named animation state on an actor while holding its position (works in both 2D and 3D scenes, with optional crossfade). ActionState Action = "state" // ActionDrop drops a 2D actor vertically from one coordinate to another. ActionDrop Action = "drop" // ActionPatrol moves a 2D actor back and forth between two coordinates. ActionPatrol Action = "patrol" // ActionMove3D moves a 3D actor (position and yaw) along a straight line or a Path3D object. ActionMove3D Action = "move3d" )
type CaptionBridge ¶
type CaptionBridge struct {
Player *Player
Track *a11y.CaptionTrack
// contains filtered or unexported fields
}
CaptionBridge mirrors a timeline player's active dialogue into a CaptionTrack, so cutscene lines get the caption settings (size, contrast, speaker colors, toggles) of CaptionsView. Call Update on the same fixed loop step as Player.Step.
func NewCaptionBridge ¶
func NewCaptionBridge(player *Player, track *a11y.CaptionTrack) *CaptionBridge
NewCaptionBridge creates a bridge for player and track. Call Update after Player.Step on each fixed update.
func (*CaptionBridge) Update ¶
func (b *CaptionBridge) Update()
Update shows a newly active dialogue line once, with its speaker, and dismisses its caption when the line ends or another replaces it, so the caption lasts as long as the dialogue clip and a replayed line shows again.
type Clip ¶
type Clip struct {
// ID optionally identifies the clip for tools and editors; non-empty clip IDs must be unique within the cutscene.
ID string `yaml:"id,omitempty"`
// Label is an optional human-readable label for the clip.
Label string `yaml:"label,omitempty"`
// Start is when the clip begins on the timeline, as a Go duration string such as "1.6s".
Start Duration `yaml:"start" schema:"required"`
// Duration is how long the clip lasts, as a Go duration string such as "2.4s".
Duration Duration `yaml:"duration" schema:"required"`
// Easing is the interpolation curve for motion, camera pans and blend ramps: "linear" (default), "easeIn", "easeOut", "easeInOut" or "hold".
Easing Easing `yaml:"easing,omitempty" schema:"enum=linear|easeIn|easeOut|easeInOut|hold"`
// Action selects the operation on a camera track ("hold", "pan", "follow" in 2D; "shot", "move", "orbit", "dolly", "useCamera" in 3D) or actor track ("walk", "state", "drop", "patrol" in 2D; "move3d", "state" in 3D).
Action Action `yaml:"action,omitempty" schema:"enum=hold|pan|follow|shot|move|orbit|dolly|useCamera|walk|state|drop|patrol|move3d"`
// Target is the scene object ID a camera clip holds on, pans to, follows, looks at, orbits or activates ("useCamera"), or an optional target object ID for a particle control clip.
Target string `yaml:"target,omitempty"`
// FromX is the optional starting X coordinate for a 2D camera pan or a 2D actor walk, drop or patrol clip.
FromX *float32 `yaml:"fromX,omitempty"`
// FromY is the optional starting Y coordinate for a 2D camera pan or a 2D actor walk, drop or patrol clip.
FromY *float32 `yaml:"fromY,omitempty"`
// ToX is the destination X coordinate for a 2D camera hold/pan or a 2D actor walk, drop or patrol clip.
ToX *float32 `yaml:"toX,omitempty"`
// ToY is the destination Y coordinate for a 2D camera hold/pan or a 2D actor walk, drop or patrol clip.
ToY *float32 `yaml:"toY,omitempty"`
// OffsetX is an optional horizontal 2D offset applied on camera clips or particle control clips.
OffsetX float32 `yaml:"offsetX,omitempty"`
// OffsetY is an optional vertical 2D offset applied on camera clips or particle control clips.
OffsetY float32 `yaml:"offsetY,omitempty"`
// Zoom is the optional target 2D camera zoom factor (positive) on a 2D camera clip.
Zoom *float32 `yaml:"zoom,omitempty" schema:"exclusiveMinimum=0"`
// Pos is the 3D world position [x, y, z] for a 3D camera "shot" clip.
Pos *[3]float32 `yaml:"pos,omitempty,flow"`
// LookAt is the 3D world look-at point [x, y, z] for a 3D camera "shot", "orbit" or "dolly" clip.
LookAt *[3]float32 `yaml:"lookAt,omitempty,flow"`
// Euler is the 3D camera orientation [pitch, yaw, roll] in degrees for a 3D camera "shot" clip.
Euler *[3]float32 `yaml:"euler,omitempty,flow"`
// FromPos is the optional starting 3D position [x, y, z] for a 3D camera "move" or 3D actor "move3d" clip; defaults to the previous pose when omitted.
FromPos *[3]float32 `yaml:"fromPos,omitempty,flow"`
// ToPos is the destination 3D position [x, y, z] for a 3D camera "move" or 3D actor "move3d" clip.
ToPos *[3]float32 `yaml:"toPos,omitempty,flow"`
// FromLookAt is the optional starting 3D look-at point [x, y, z] for a 3D camera "move" clip.
FromLookAt *[3]float32 `yaml:"fromLookAt,omitempty,flow"`
// ToLookAt is the destination 3D look-at point [x, y, z] for a 3D camera "move" clip.
ToLookAt *[3]float32 `yaml:"toLookAt,omitempty,flow"`
// FromEuler is the optional starting 3D orientation [pitch, yaw, roll] in degrees for a 3D camera "move" clip.
FromEuler *[3]float32 `yaml:"fromEuler,omitempty,flow"`
// ToEuler is the destination 3D orientation [pitch, yaw, roll] in degrees for a 3D camera "move" clip.
ToEuler *[3]float32 `yaml:"toEuler,omitempty,flow"`
// Offset is an optional 3D world-space offset [x, y, z] added to a 3D camera clip's target object position.
Offset *[3]float32 `yaml:"offset,omitempty,flow"`
// FOV is the optional vertical field of view in degrees, in (0, 180), for 3D camera clips ("shot", "move", "orbit", "dolly", "useCamera").
FOV *float32 `yaml:"fov,omitempty" schema:"exclusiveMinimum=0,exclusiveMaximum=180"`
// FromFOV is the optional starting vertical field of view in degrees, in (0, 180), for a 3D camera "move" clip.
FromFOV *float32 `yaml:"fromFov,omitempty" schema:"exclusiveMinimum=0,exclusiveMaximum=180"`
// Path names a Path3D scene object ID followed by a 3D camera "dolly" clip or a 3D actor "move3d" clip.
Path string `yaml:"path,omitempty"`
// Radius is the orbit distance (positive) around the target or lookAt center for a 3D camera "orbit" clip.
Radius *float32 `yaml:"radius,omitempty" schema:"exclusiveMinimum=0"`
// Height is the vertical offset above the orbit center for a 3D camera "orbit" clip; defaults to 0.
Height *float32 `yaml:"height,omitempty"`
// StartAngle is the starting azimuth angle in degrees around +Y (0 = +Z, 90 = +X) for a 3D camera "orbit" clip; defaults to 0.
StartAngle *float32 `yaml:"startAngle,omitempty"`
// EndAngle is the ending azimuth angle in degrees around +Y for a 3D camera "orbit" clip.
EndAngle *float32 `yaml:"endAngle,omitempty"`
// FromYaw is the optional starting yaw angle in degrees around +Y for a 3D actor "move3d" clip; defaults to the actor's current yaw when omitted.
FromYaw *float32 `yaml:"fromYaw,omitempty"`
// ToYaw is the optional ending yaw angle in degrees around +Y for a 3D actor "move3d" clip; when omitted, the actor faces its direction of motion.
ToYaw *float32 `yaml:"toYaw,omitempty"`
// FromRot is the optional starting rotation [x, y, z] in degrees for a 3D actor "move3d" clip, applied like a scene object's rotX, rotY and rotZ (about fixed X, then Y, then Z axes); defaults to the actor's current rotation when omitted.
FromRot *[3]float32 `yaml:"fromRot,omitempty,flow"`
// ToRot is the optional ending rotation [x, y, z] in degrees for a 3D actor "move3d" clip, applied like a scene object's rotX, rotY and rotZ; the rotation is interpolated with slerp, and it replaces fromYaw, toYaw and facing the direction of motion.
ToRot *[3]float32 `yaml:"toRot,omitempty,flow"`
// FromScale is the optional starting scale [x, y, z] for a 3D actor "move3d" clip; defaults to the actor's current scale when omitted.
FromScale *[3]float32 `yaml:"fromScale,omitempty,flow"`
// ToScale is the optional ending scale [x, y, z] for a 3D actor "move3d" clip, interpolated per axis.
ToScale *[3]float32 `yaml:"toScale,omitempty,flow"`
// State is the animation state name played by an actor clip (required for "state" clips, optional for "walk", "drop", "patrol" and "move3d").
State string `yaml:"state,omitempty"`
// Crossfade is the optional anim3d crossfade duration for an actor "state" or "move3d" clip, written as a Go duration string such as "200ms".
Crossfade Duration `yaml:"crossfade,omitempty"`
// Speed is the optional travel speed in world units per second for a 2D actor "patrol" clip; when omitted, patrol completes one full round-trip over Duration.
Speed *float32 `yaml:"speed,omitempty" schema:"exclusiveMinimum=0"`
// Line is the localization key (for example "intro.knight.01") shown by a dialogue clip; text lives in the l10n tables, not in the cutscene file.
Line string `yaml:"line,omitempty"`
// Speaker optionally names who speaks a dialogue clip.
Speaker string `yaml:"speaker,omitempty"`
// Source is the audio path or URI for a sound or music clip (for example "audio/door_slam.wav").
Source string `yaml:"source,omitempty"`
// Group overrides the track's mixer group for a sound or music clip.
Group string `yaml:"group,omitempty"`
// Volume is the optional volume multiplier in [0, 1] for a sound or music clip; defaults to 1 when omitted.
Volume *float32 `yaml:"volume,omitempty" schema:"minimum=0,maximum=1"`
// FadeIn is the fade-in duration for a music clip, as a Go duration string such as "2s".
FadeIn Duration `yaml:"fadeIn,omitempty"`
// FadeOut is the fade-out duration for a music clip, as a Go duration string such as "1s".
FadeOut Duration `yaml:"fadeOut,omitempty"`
// Loop repeats a music clip until its duration ends.
Loop bool `yaml:"loop,omitempty"`
// Animation is the project-relative path to a resource.Animation file played by an "animation" track clip.
Animation string `yaml:"animation,omitempty"`
// EaseIn is the blend-in duration at the start of an "animation" or custom track clip, as a Go duration string such as "200ms".
EaseIn Duration `yaml:"easeIn,omitempty"`
// EaseOut is the blend-out duration at the end of an "animation" or custom track clip, as a Go duration string such as "200ms".
EaseOut Duration `yaml:"easeOut,omitempty"`
// Hold keeps the clip's final pose after an "animation" or custom track clip ends instead of restoring the pre-clip values.
Hold bool `yaml:"hold,omitempty"`
// Cutscene is the project-relative path to a nested timeline cutscene file played by a "control" track clip.
Cutscene string `yaml:"cutscene,omitempty"`
// Particles is the project-relative path to a 2D particle emitter YAML definition played by a "control" track clip.
Particles string `yaml:"particles,omitempty"`
// Custom holds arbitrary structured fields validated and consumed by a game-registered custom track kind, encoded in deterministic sorted key order.
Custom map[string]any `yaml:"custom,omitempty"`
}
Clip is one timed action or cue on a cutscene timeline track.
func (Clip) MarshalYAML ¶
MarshalYAML encodes c with Custom map keys sorted in deterministic lexicographical order.
type Cutscene ¶
type Cutscene struct {
// Version is the file format's version, from MinVersion (1) to CurrentVersion (2), which Parse and Encode check. Player.Play and NewTimelinePlayer ignore it, so a cutscene made in code may leave it 0.
Version int `yaml:"version" schema:"required"`
// Kind selects whether a version 2 cutscene plays a video ("video") or an in-engine timeline ("timeline"). Version 1 files leave it empty.
Kind Kind `yaml:"kind,omitempty" schema:"enum=video|timeline"`
// Source is the video for a video cutscene: an "asset:" path in the app's resources, a file path or a URL, as core.Video takes. Omitted on timeline cutscenes.
Source string `yaml:"source,omitempty"`
// Scene optionally names the scene file a timeline cutscene plays against, as a slash-separated path from the project root (for example "scenes/level_01.scene.yaml"). Used by game check and refs to validate object IDs. Version 2 timeline cutscenes only.
Scene string `yaml:"scene,omitempty"`
// Length is the total duration of a timeline cutscene, written as a Go duration string such as "12s". Version 2 timeline cutscenes only.
Length Duration `yaml:"length,omitempty"`
// BlendOut is the trailing duration over which a 3D timeline cutscene blends its camera back to the gameplay camera with scene3d.Camera.Lerp; 0 cuts directly. Version 2 timeline cutscenes only.
BlendOut Duration `yaml:"blendOut,omitempty"`
// Group is the mixer group whose volume, times the master volume, the cutscene's audio plays at; empty for the master volume alone (video) or per-track defaults (timeline).
Group string `yaml:"group,omitempty"`
// Skippable lets the player skip the cutscene by a press, a skip key or back.
Skippable bool `yaml:"skippable,omitempty"`
// SkipAfter is how far into the cutscene a skippable cutscene must play before it can be skipped, so a press meant for the game before it does not skip it at once; 0 for from the start.
SkipAfter Duration `yaml:"skipAfter,omitempty"`
// Fit is how a video cutscene's picture fits the screen, FitContain when empty. Video cutscenes only.
Fit Fit `yaml:"fit,omitempty" schema:"enum=contain|cover|stretch"`
// Transparent leaves the screen behind a video cutscene clear rather than black, so the game shows in the bars and through a video with an alpha channel, where the platform keeps it (core.Video). Video cutscenes only.
Transparent bool `yaml:"transparent,omitempty"`
// Tracks are the ordered timeline tracks (camera, actor, dialogue, sound and music) of a timeline cutscene. Version 2 timeline cutscenes only.
Tracks []Track `yaml:"tracks,omitempty"`
}
Cutscene is one video or timeline cutscene, and the document a cutscene file holds.
Version 1 holds a video cutscene:
version: 1 source: asset:cutscenes/intro.mp4 group: cutscenes skippable: true skipAfter: 1.5s fit: cover
Version 2 holds either a video cutscene or an in-engine timeline cutscene with camera, actor, dialogue, sound and music tracks:
# yaml-language-server: $schema=https://nsgo.games/schemas/cutscene.v2.json
version: 2
kind: timeline
scene: scenes/level_01.scene.yaml
length: 12s
skippable: true
tracks:
- kind: camera
clips:
- start: 0s
duration: 1.6s
easing: hold
action: hold
target: door
Parse reads such a file and Encode writes one, keys in the order of the fields below and zero values left out, so a file Encode wrote reads back and writes again unchanged.
func Parse ¶
Parse reads a cutscene file and checks it as Validate does. It refuses unknown keys, more than one document and a version outside [MinVersion, CurrentVersion].
Example ¶
Parse reads a cutscene file, refusing unknown keys, and Encode writes it back unchanged.
package main
import (
"fmt"
"time"
"github.com/nsgo-dev/game/pkg/cutscene"
)
const introFile = `version: 1
source: asset:cutscenes/intro.mp4
group: cutscenes
skippable: true
skipAfter: 1.5s
fit: cover
`
func main() {
c, err := cutscene.Parse([]byte(introFile))
fmt.Println(err, c.Source, c.Skippable, time.Duration(c.SkipAfter), c.Fit)
out, _ := cutscene.Encode(c)
fmt.Println(string(out) == introFile)
_, err = cutscene.Parse([]byte(introFile + "volume: 0.5\n"))
fmt.Println(err != nil)
}
Output: <nil> asset:cutscenes/intro.mp4 true 1.5s cover true true
func (Cutscene) EffectiveKind ¶
EffectiveKind reports whether c is a video cutscene or a timeline cutscene.
type DialogueLine ¶
type DialogueLine struct {
// ID is the localization line ID (for example "intro.knight.01"), empty when no dialogue clip is active.
ID string
// Speaker is the clip's optional speaker name.
Speaker string
// Text is the localized text resolved from the l10n catalog, or ID when no catalog is configured.
Text string
// Active reports whether a dialogue clip is active.
Active bool
}
DialogueLine is the dialogue cue active at the current timeline position.
type Duration ¶
Duration is a time.Duration written in a cutscene file as Go writes durations, such as "1.5s" or "250ms".
func (Duration) MarshalYAML ¶
MarshalYAML writes d as time.Duration.String does.
type Easing ¶
type Easing string
Easing selects the interpolation curve of a timeline clip.
const ( // EaseLinear interpolates at a constant rate. It is the default when omitted. EaseLinear Easing = "linear" // EaseIn starts slowly and accelerates using core.EaseIn. EaseIn Easing = "easeIn" // EaseOut starts quickly and decelerates using core.EaseOut. EaseOut Easing = "easeOut" // EaseInOut eases smoothly at both ends using core.EaseInOut. EaseInOut Easing = "easeInOut" // EaseHold holds the starting value until the end of the clip, then steps to the target value. EaseHold Easing = "hold" )
type Fit ¶
type Fit string
Fit says how a video cutscene's picture fits the screen.
const ( // FitContain shows the whole picture, with bars where its shape differs from the screen's. It is the default. FitContain Fit = "contain" // FitCover fills the screen, cropping what overflows. FitCover Fit = "cover" // FitStretch fills the screen, distorting the picture. FitStretch Fit = "stretch" )
type Kind ¶
type Kind string
Kind selects whether a cutscene plays a video or an in-engine timeline.
type Marker ¶
type Marker struct {
// ID optionally identifies the marker for tools and editors; non-empty marker IDs must be unique within the cutscene.
ID string `yaml:"id,omitempty"`
// At is when the marker fires on the timeline, as a Go duration string such as "4.2s".
At Duration `yaml:"at" schema:"required"`
// Name is the signal name delivered to TimelineTarget.OnSignal, such as "gate_open".
Name string `yaml:"name" schema:"required,minLength=1"`
// Args are optional named scalar arguments (string, finite number or boolean) passed to OnSignal, encoded in sorted key order.
Args map[string]any `yaml:"args,omitempty"`
// OnSkip controls whether an unfired marker fires when the player skips the cutscene: "ignore" (default) or "fire".
OnSkip SkipBehavior `yaml:"onSkip,omitempty" schema:"enum=ignore|fire"`
}
Marker is one timed signal cue on a "signal" timeline track.
func (Marker) MarshalYAML ¶
MarshalYAML encodes m with Args keys sorted in deterministic lexicographical order.
type Options ¶
type Options struct {
// Loop is the game's loop, paused while a video cutscene plays (game.Loop.SetPaused) and set back as it was when it ends; nil for none. Draw goes on running under the video, as for any paused loop. Timeline cutscenes leave the loop running so the game steps them with Player.Step on fixed updates.
Loop *game.Loop
// Mixer is the game's mixer, suspended while a video cutscene plays (sound.Mixer.Suspend) and resumed when it ends. Its master volume, times the cutscene's group's, sets how loud the video plays. For timeline cutscenes, Mixer is used as the default TimelineTarget.Mixer when the target leaves it nil. Nil leaves the game's sound alone and plays video at full volume.
Mixer *sound.Mixer
// SkipKeys are the keys that skip a skippable cutscene, as core.Scope.OnKey names them; nil for "enter" and "space", and an empty slice for none. A press on the cutscene view and back (Escape, the back button or gesture, the browser's back) skip it too.
SkipKeys []string
// TestID is the cutscene view's test ID, "cutscene" when empty.
TestID string
}
Options are what a Player pauses while a video cutscene plays and how cutscenes are skipped.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player plays one cutscene at a time over a game's view: either a video cutscene (Play, pausing the game's loop and mixer) or an in-engine timeline cutscene (PlayTimeline, stepped on the game's fixed loop via Step).
Mount View over the game's view, as the last child of the view that holds the game's canvas, so a video covers it and a timeline cutscene receives skip input. Play and PlayTimeline start a cutscene from a game's Update or anywhere else on the engine's goroutine, and Scene / TimelineScene make one a scene of its own to play between scenes.
Video cutscenes play in the platform's player (core.Video). It pauses while the app is in the background and plays on as it returns; when the platform pauses it itself, as for a call or headphones unplugged, a press or a skip key plays it on rather than skipping it.
Its methods are called on the engine's goroutine, as core's are.
Example ¶
A Player pauses the game's loop while a cutscene plays and sets it back before calling done. Here a root scope stands in for the app and the game skips the cutscene itself; in an app, mount Player.View over the game's view so the video shows and a press, a skip key or back skips it.
package main
import (
"fmt"
"time"
"github.com/nsgo-dev/game"
"github.com/nsgo-dev/game/pkg/cutscene"
"github.com/nsgo-dev/nsgo/core"
)
func main() {
root := core.NewRoot(core.RootOptions{})
defer root.Dispose()
loop := &game.Loop{Update: func(time.Duration) {}}
defer loop.Run(root)()
player := cutscene.NewPlayer(root, cutscene.Options{Loop: loop})
err := player.Play(cutscene.Cutscene{Source: "asset:cutscenes/intro.mp4", Skippable: true}, func(r cutscene.Result) {
fmt.Println("done:", r.Reason, "loop paused:", loop.Paused)
})
fmt.Println(err, player.Playing(), loop.Paused, player.CanSkip())
fmt.Println(player.Skip(), player.Playing())
// A cutscene with no source plays nothing.
fmt.Println(player.Play(cutscene.Cutscene{}, nil) != nil)
}
Output: <nil> true true true done: skipped loop paused: false true false true
func NewPlayer ¶
NewPlayer returns a player that lives as long as cx. Disposing cx while a cutscene plays stops it without calling its done callback, and sets the loop and the mixer back as they were.
func (*Player) Camera3D ¶
Camera3D returns the active 3D camera of the playing timeline cutscene and true, or the zero camera and false when no 3D timeline cutscene is playing.
func (*Player) CanSkip ¶
CanSkip reports whether the cutscene playing can be skipped now: it is Skippable and played past SkipAfter. Read in a computation, it subscribes it to changes, so a game can show its own skip prompt over the video or scene only while a skip would work.
func (*Player) Dialogue ¶
func (p *Player) Dialogue() DialogueLine
Dialogue returns the active dialogue line of the playing timeline cutscene. Read in a view or computation, it subscribes to changes so a HUD can render subtitles automatically.
func (*Player) Play ¶
Play plays a video cutscene c over the game, pausing the loop and the mixer until it ends, and then calls done, which may be nil, with how it ended; the loop and the mixer are back as they were by then, so done may play another cutscene or switch scenes. A cutscene playing already stops first, its done callback told Stopped.
It returns an error, and plays nothing, for a timeline cutscene (use PlayTimeline), a video cutscene with no source, an unknown Fit or a negative SkipAfter, and ErrReplaced when the stopped cutscene's done callback plays another cutscene, which then plays in its place.
func (*Player) PlayTimeline ¶
func (p *Player) PlayTimeline(c Cutscene, target TimelineTarget, done func(Result)) (*TimelinePlayer, error)
PlayTimeline starts a timeline cutscene c against target, wiring skip keys, press-to-skip, back handling, CanSkip and Dialogue through p. Call Step(dt) on game.Loop's fixed Update to advance it; the game's loop and mixer keep running so the scene draws and plays cutscene audio.
A cutscene playing already stops first, its done callback told Stopped. Returns ErrReplaced if that done callback started another cutscene.
func (*Player) Playing ¶
Playing reports whether a cutscene plays. Read in a computation, it subscribes it to changes, as a core.Signal does.
func (*Player) Scene ¶
Scene returns a scene that plays video cutscene c as it enters and calls done as it ends, for a cutscene between two scenes: switch to it, and switch on from done.
intro, err := player.Scene(c, func(cutscene.Result) { scenes.Switch(level1, fade) })
if err == nil {
scenes.Switch(intro, nil)
}
Leaving the scene before the cutscene ends stops it without calling done, also when the scene switched to is another cutscene scene of the same player entered with a transition, which enters before the scene it replaces exits. It returns an error for a cutscene Play would refuse.
func (*Player) Skip ¶
Skip ends the cutscene playing with Skipped, as the player's skip input does, and reports whether it did: not while none plays or it cannot be skipped yet (CanSkip).
func (*Player) Step ¶
Step advances an active timeline cutscene by dt on game.Loop's fixed Update step. Does nothing when no timeline cutscene is playing.
func (*Player) Stop ¶
Stop ends the cutscene playing with Stopped, skippable or not, and reports whether one played.
func (*Player) TimelineScene ¶
func (p *Player) TimelineScene(c Cutscene, target TimelineTarget, done func(Result)) (*scene.Controller, error)
TimelineScene returns a scene that plays timeline cutscene c against target as it enters and calls done as it ends. Leaving the scene early stops the cutscene without calling done.
type Reason ¶
type Reason uint8
Reason says how a cutscene ended.
const ( // Finished is a cutscene that played to its end. Finished Reason = iota // Skipped is a cutscene the player skipped, by a press, a skip key, back or Player.Skip. Skipped // Stopped is a cutscene the game stopped, by Player.Stop or by playing another one over it. Stopped // Failed is a cutscene the platform could not open or play, such as a missing file or a codec it lacks. Failed )
type Result ¶
type Result struct {
// Reason says how it ended.
Reason Reason
// Position is how far into the cutscene it played (for video, as the platform last reported; for timeline, the elapsed timeline duration); 0 when it reported nothing.
Position time.Duration
// Err is why it failed, a *core.MediaError from the platform, for Failed; nil otherwise.
Err error
}
Result is how a cutscene ended, which Player.Play and Player.PlayTimeline hand their done callback.
type Scene3DTarget ¶
type Scene3DTarget struct {
// Built, when non-nil, supplies the built 3D scene's node tree (Built.Objects), camera objects (Built.Cameras), and Path3D objects (via each node's *sceneformat.ObjectDoc UserData).
Built *scenemodel.Built
// Renderer, when non-nil, names the scenemodel.Renderer associated with Built; Built's nodes are updated in place before the caller runs Prepare/Draw.
Renderer *scenemodel.Renderer
// Doc, when non-nil, supplies the source SceneDoc for Path3D curves, 3D cameras and initial 3D transforms when Built is nil or omits an object.
Doc *sceneformat.SceneDoc
// Node, when non-nil, resolves a scene object ID to its *scene3d.Node (taking precedence over Built.Objects when both are provided).
Node func(id string) *scene3d.Node
// StateMachine, when non-nil, resolves an actor ID to its *anim3d.StateMachine so actor "state" and "move3d" clips call SetState(state, crossfade).
StateMachine func(actorID string) *anim3d.StateMachine
// Graph, when non-nil, resolves an actor ID to its *anim3d.Graph so actor "state" and "move3d" clips drive the graph's state machine when StateMachine returns nil.
Graph func(actorID string) *anim3d.Graph
// GameplayCamera, when non-nil, returns the gameplay camera that Cutscene.BlendOut blends into with scene3d.Camera.Lerp over the final BlendOut window. When nil, BlendOut blends back to the scene's initial 3D camera.
GameplayCamera func() scene3d.Camera
// Aspect is the viewport width/height ratio used for 3D camera clips; defaults to GameplayCamera's aspect, or 16/9 when <= 0.
Aspect float32
// Near is the default near clip plane distance for synthesized 3D cameras; defaults to 0.1 when <= 0.
Near float32
// Far is the default far clip plane distance for synthesized 3D cameras; defaults to 1000 when <= Near.
Far float32
// OnActorPose3D, when non-nil, is called whenever a 3D actor's position or yaw is applied (pos in world/local meters, yaw in radians around +Y where 0 faces -Z).
OnActorPose3D func(actorID string, pos math3d.Vec3, yaw float32)
}
Scene3DTarget connects a TimelinePlayer to a 3D scene: a built scenemodel scene and/or renderer, node lookup, anim3d state machines or animation graphs, gameplay camera for blendOut, and default projection parameters.
type SkipBehavior ¶
type SkipBehavior string
SkipBehavior controls whether an unfired signal marker still fires when the player skips the cutscene.
const ( // SkipIgnore leaves an unfired marker unfired when the cutscene is skipped. It is the default when omitted. SkipIgnore SkipBehavior = "ignore" // SkipFire fires an unfired marker in timeline order when the cutscene is skipped so world-state changes still happen. SkipFire SkipBehavior = "fire" )
type TimelinePlayer ¶
type TimelinePlayer struct {
// contains filtered or unexported fields
}
TimelinePlayer runs a version 2 timeline cutscene deterministically on game.Loop's fixed steps against a scene.
Call Play to begin, Update(dt) on each fixed loop step, Seek(at) to scrub to any timestamp without firing audio or completion callbacks, and Skip or Stop to end early.
func NewTimelinePlayer ¶
func NewTimelinePlayer(c Cutscene, target TimelineTarget) (*TimelinePlayer, error)
NewTimelinePlayer validates c as a timeline cutscene, resolves its scene objects against target.Scene, target.Scene3D or target.Doc (when provided), snapshots initial poses and returns a player positioned at time 0.
func (*TimelinePlayer) ActiveDialogue ¶
func (p *TimelinePlayer) ActiveDialogue() DialogueLine
ActiveDialogue returns the dialogue line active at the current position.
func (*TimelinePlayer) ActiveParticleEmitters ¶
func (p *TimelinePlayer) ActiveParticleEmitters() []*particles.Emitter
ActiveParticleEmitters returns the live particle emitters currently active on control tracks (including active nested cutscenes).
func (*TimelinePlayer) ActorPose3D ¶
ActorPose3D returns the current 3D position and yaw (radians around +Y, 0 faces -Z) of actorID and whether it is tracked in 3D.
func (*TimelinePlayer) ActorPosition ¶
func (p *TimelinePlayer) ActorPosition(actorID string) (x, y float32, ok bool)
ActorPosition returns the current (x, y) position of actorID and whether it is tracked.
func (*TimelinePlayer) ActorState ¶
func (p *TimelinePlayer) ActorState(actorID string) string
ActorState returns the active animation state of actorID, or "" when none is active.
func (*TimelinePlayer) Camera3D ¶
func (p *TimelinePlayer) Camera3D() (scene3d.Camera, bool)
Camera3D returns the 3D camera at the current timeline position (after applying Cutscene.BlendOut when in the blend-out window) and whether the timeline has a 3D camera pose.
func (*TimelinePlayer) CameraState ¶
func (p *TimelinePlayer) CameraState() (x, y, zoom float32, ok bool)
CameraState returns the camera's current (x, y, zoom) and whether the timeline has set the camera.
func (*TimelinePlayer) CanSkip ¶
func (p *TimelinePlayer) CanSkip() bool
CanSkip reports whether the cutscene is currently playing and can be skipped now.
func (*TimelinePlayer) Cutscene ¶
func (p *TimelinePlayer) Cutscene() Cutscene
Cutscene returns the cutscene definition p plays.
func (*TimelinePlayer) Done ¶
func (p *TimelinePlayer) Done() bool
Done reports whether playback has ended (finished, skipped or stopped).
func (*TimelinePlayer) DrawParticles ¶
func (p *TimelinePlayer) DrawParticles(d *core.Drawing)
DrawParticles draws every active control-track particle emitter (including emitters inside active nested cutscenes) into d.
func (*TimelinePlayer) Length ¶
func (p *TimelinePlayer) Length() time.Duration
Length returns the cutscene's total duration.
func (*TimelinePlayer) ObjectActive ¶
func (p *TimelinePlayer) ObjectActive(target string) (active bool, ok bool)
ObjectActive reports whether target is currently active on an activation track, and whether an activation track controls target.
func (*TimelinePlayer) Pause ¶
func (p *TimelinePlayer) Pause()
Pause pauses playback at the current position without ending the cutscene.
func (*TimelinePlayer) Play ¶
func (p *TimelinePlayer) Play()
Play starts or resumes playback from the current position. A finished cutscene stays finished until Reset is called.
func (*TimelinePlayer) Playing ¶
func (p *TimelinePlayer) Playing() bool
Playing reports whether playback is active.
func (*TimelinePlayer) Reset ¶
func (p *TimelinePlayer) Reset()
Reset rewinds to time 0, restores initial actor, object and camera poses, stops active cutscene music and clears done state.
func (*TimelinePlayer) Seek ¶
func (p *TimelinePlayer) Seek(at time.Duration)
Seek jumps directly to timestamp at (clamped to [0, Length]) and applies all actor, animation, activation, control, camera, dialogue and custom track states deterministically without firing signals, sound, music or completion callbacks.
func (*TimelinePlayer) Skip ¶
func (p *TimelinePlayer) Skip() bool
Skip ends playback with Skipped if the cutscene is playing and CanSkip reports true, applying the timeline's final poses deterministically (including BlendOut) while reporting the timestamp at which the player skipped. Any unfired signal markers with onSkip: fire (including those in nested cutscenes) fire in timeline order before OnDone.
func (*TimelinePlayer) Stop ¶
func (p *TimelinePlayer) Stop() bool
Stop ends playback with Stopped regardless of Skippable, reporting whether the cutscene was active (playing or paused mid-cutscene).
func (*TimelinePlayer) Time ¶
func (p *TimelinePlayer) Time() time.Duration
Time returns the current playback position in [0, Length].
func (*TimelinePlayer) Update ¶
func (p *TimelinePlayer) Update(dt time.Duration)
Update advances a playing timeline cutscene by dt on a fixed game.Loop step.
func (*TimelinePlayer) VirtualCamera ¶
func (p *TimelinePlayer) VirtualCamera() *camera.VirtualCamera
VirtualCamera returns a camera.VirtualCamera that reflects this timeline player's current 2D or 3D camera pose. When TimelineTarget.Director is set, the VirtualCamera is registered automatically at CutscenePriority, enabled on Play, and disabled on Reset/Finish/Skip/Stop.
type TimelineTarget ¶
type TimelineTarget struct {
// Scene, when non-nil, is the built 2D scene whose objects and camera the player drives directly.
// Actor clips update BuiltObject.Doc.X/Y and call BuiltObject.Sync; camera clips update Scene.Camera.
Scene *sceneformat.BuiltScene
// Scene3D, when non-nil, connects the player to a 3D scene (scenemodel.Built, scenemodel.Renderer, node lookup, anim3d state machines and gameplay camera for blendOut).
Scene3D *Scene3DTarget
// Doc, when non-nil and Scene/Scene3D are nil, is a SceneDoc whose objects and camera the player drives directly.
Doc *sceneformat.SceneDoc
// Catalog, when non-nil, resolves dialogue clip line IDs into localized text for ActiveDialogue and OnDialogue.
Catalog *l10n.Catalog
// Locale is the BCP-47 locale tag passed to Catalog.T; when empty, Catalog.FallbackLocale is used.
Locale string
// Mixer, when non-nil, plays music clips through sound.Mixer when OnMusic is nil.
Mixer *sound.Mixer
// AudioSource maps a clip's Source path to an audio.Source when playing through Mixer; when nil, audio.Source{URI: source} is used.
AudioSource func(source string) audio.Source
// FS, when non-nil, reads animation resources, nested cutscene files and particle definitions referenced by animation and control tracks when their dedicated loader callback is nil.
FS fs.FS
// CutscenePath optionally records this cutscene's project-relative path so self-referential nested cutscenes are detected as cycles immediately.
CutscenePath string
// LoadAnimation, when non-nil, loads a *resource.Animation for an "animation" track clip; when nil, FS is read and parsed with resource.ParseAs[*resource.Animation].
LoadAnimation func(path string) (*resource.Animation, error)
// LoadCutscene, when non-nil, loads a nested Cutscene for a "control" track cutscene clip; when nil, FS is read and parsed with Parse.
LoadCutscene func(path string) (Cutscene, error)
// LoadParticles, when non-nil, loads a particles.Config for a "control" track particle clip; when nil, FS is read and parsed with particles.UnmarshalConfigYAML.
LoadParticles func(path string) (particles.Config, error)
// OnActorState is called whenever an actor track's active state changes (and with "" when leaving a state clip).
OnActorState func(actorID, state string)
// OnDialogue is called whenever the active dialogue line changes.
OnDialogue func(line DialogueLine)
// OnSound is called once when Update crosses a sound clip's Start (never during Seek).
OnSound func(clip Clip, group string, volume float32)
// OnMusic is called once when Update crosses a music clip's Start (never during Seek).
OnMusic func(clip Clip, group string, volume float32)
// OnMusicStop is called when an active music clip ends or the cutscene ends, skips or stops.
OnMusicStop func(clip Clip, fadeOut time.Duration)
// OnSignal is called once when Update crosses a signal track marker (never during Seek), and in timeline order when Skip is called for unfired markers with onSkip: fire.
OnSignal func(name string, args map[string]any)
// OnActivation is called whenever an activation track's target visibility changes.
OnActivation func(target string, active bool)
// OnControlParticles is called when a control track's particle emitter becomes active or inactive (allowing the game to bind an atlas/frames or observe lifecycle).
OnControlParticles func(clip Clip, emitter *particles.Emitter, active bool)
// OnDone is called once when the cutscene finishes, is skipped or is stopped.
OnDone func(Result)
// Director, when non-nil, automatically receives a cutscene VirtualCamera while the timeline plays and disables it on finish, skip, stop, or reset so the Director blends back to gameplay.
Director *camera.Director
// CutscenePriority is the priority assigned to the timeline's VirtualCamera on Director (defaults to 1000 when 0).
CutscenePriority int
}
TimelineTarget connects a TimelinePlayer to a scene, localization catalog, audio callbacks and mixer.
type Track ¶
type Track struct {
// ID optionally identifies the track for tools and editors; non-empty track IDs must be unique within the cutscene.
ID string `yaml:"id,omitempty"`
// Name is an optional human-readable display label for the track.
Name string `yaml:"name,omitempty"`
// Kind selects what the track drives: "camera", "actor", "dialogue", "sound", "music", "signal", "activation", "animation", "control" or a registered "<namespace>.<name>" track kind.
Kind TrackKind `yaml:"kind" schema:"required,minLength=1"`
// Target is the scene object ID driven by an "actor", "activation" or "animation" track (required for those kinds), or an optional target object ID on a "control" or custom track.
Target string `yaml:"target,omitempty"`
// Group is the default mixer group for audio clips on a "sound" or "music" track (defaults to "sfx" for sound and "music" for music).
Group string `yaml:"group,omitempty"`
// Clips are the timed clips on this track, in non-decreasing start order. Omitted on "signal" tracks.
Clips []Clip `yaml:"clips,omitempty"`
// Markers are the timed signal cues on a "signal" track, in non-decreasing time order. Omitted on non-signal tracks.
Markers []Marker `yaml:"markers,omitempty"`
}
Track is one lane on a timeline cutscene (camera, actor, dialogue, sound, music, signal, activation, animation, control or a registered custom kind) holding timed clips or signal markers.
type TrackClipContext ¶
type TrackClipContext struct {
// Track is the enclosing custom track definition.
Track Track
// Clip is the clip being validated or instantiated for playback.
Clip Clip
// Target is the live TimelineTarget when NewTimelinePlayer constructs an evaluator,
// or nil when Parse or Validate validates the clip's custom fields at load time.
Target *TimelineTarget
}
TrackClipContext passes the enclosing track, the clip (with a defensive copy of Custom) and the optional TimelineTarget to a registered track kind's factory.
type TrackEvaluator ¶
TrackEvaluator evaluates a single clip on a game-registered custom timeline track.
TimelinePlayer calls Evaluate during Update and Seek whenever the clip is active, passing the clip-local elapsed time t in [0, clip.Duration] and a blend weight in [0, 1] shaped by the clip's easeIn, easeOut and easing.
type TrackEvaluatorFunc ¶
TrackEvaluatorFunc adapts a function into a TrackEvaluator.
type TrackKind ¶
type TrackKind string
TrackKind selects what a timeline track's clips drive.
const ( // TrackCamera drives the scene camera (hold on an object or point, pan to, follow). TrackCamera TrackKind = "camera" // TrackActor drives a named scene object (walk, play an animation state, drop, patrol). TrackActor TrackKind = "actor" // TrackDialogue drives timed localized dialogue lines by l10n key. TrackDialogue TrackKind = "dialogue" // TrackSound triggers one-shot sound effects. TrackSound TrackKind = "sound" // TrackMusic plays background music tracks with optional fade-in and fade-out. TrackMusic TrackKind = "music" // TrackSignal fires named markers with scalar arguments when playback crosses them. TrackSignal TrackKind = "signal" // TrackActivation shows a target scene object only while a clip on the track is active. TrackActivation TrackKind = "activation" // TrackAnimation plays authored resource.Animation clips on a target scene object with ease-in and ease-out weights. TrackAnimation TrackKind = "animation" // TrackControl plays time-synced nested timeline cutscene files or particle emitter definitions. TrackControl TrackKind = "control" )
func TrackKinds ¶
func TrackKinds() []TrackKind
TrackKinds returns every timeline track kind this package accepts: the built-in kinds in a fixed order followed by any game-registered kinds in sorted order.
type TrackKindSpec ¶
type TrackKindSpec struct {
// Kind is the namespaced track kind written in YAML, in "<namespace>.<name>" form such as "mygame.lights".
Kind TrackKind
// Label is an optional human-readable display name shown in tools such as the editor timeline.
Label string
// RequiresTarget, when true, requires tracks of this kind to name a non-empty Target scene object ID.
RequiresTarget bool
// AllowOverlap, when true, allows clips on tracks of this kind to overlap in time.
AllowOverlap bool
// New validates ctx.Clip.Custom and returns a non-nil TrackEvaluator for the clip.
// It is called both during Parse/Validate (with ctx.Target == nil) and during NewTimelinePlayer
// (with ctx.Target != nil). Returning a *loaderr.Error with Field set attaches the error under
// tracks[i].clips[j].custom.<field>.
New func(ctx TrackClipContext) (TrackEvaluator, error)
}
TrackKindSpec describes a game- or plugin-registered custom timeline track kind.
func LookupTrackKind ¶
func LookupTrackKind(kind TrackKind) (TrackKindSpec, bool)
LookupTrackKind returns the registered TrackKindSpec for kind, if any.
type TrackResetter ¶
type TrackResetter interface {
Reset()
}
TrackResetter may optionally be implemented by a TrackEvaluator to restore state when playback leaves the clip (unless the clip sets hold: true) or when TimelinePlayer.Reset runs.