La referencia de API proviene de los comentarios de documentación de Go en el código fuente y está redactada en inglés.
package cutscene
import "github.com/nsgo-dev/game/pkg/cutscene"Resumen
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.
Índice
- Constantes
- Variables
- func Encode(c Cutscene) ([]byte, error)
- func SchemaCommentFor(version int) string
- func Validate(c Cutscene) error
- type Action
- type Clip
- type Cutscene
- type DialogueLine
- type Duration
- type Easing
- type Fit
- type Kind
- type Options
- type Player
- func NewPlayer(cx *core.Scope, opts Options) *Player
- 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 TimelinePlayer
- func NewTimelinePlayer(c Cutscene, target TimelineTarget) (*TimelinePlayer, error)
- func (p *TimelinePlayer) ActiveDialogue() DialogueLine
- func (p *TimelinePlayer) ActorPosition(actorID string) (x, y float32, ok bool)
- func (p *TimelinePlayer) ActorState(actorID string) string
- 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) Length() time.Duration
- 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)
- type TimelineTarget
- type Track
- type TrackKind
Constantes
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
// SchemaURL is where the JSON Schema of version 1 cutscene files is published.
SchemaURL = "https://game.nsgo.dev/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://game.nsgo.dev/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.
Funciones
func Encode(c Cutscene) ([]byte, error)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 SchemaCommentFor(version int) stringSchemaCommentFor returns the YAML language server schema comment for version: SchemaComment for version 1 and SchemaCommentV2 for version 2.
func Validate(c Cutscene) errorValidate 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.
Tipos
type Action stringAction selects what a camera or actor clip does.
const (
// ActionHold holds the camera on a target object or fixed coordinates.
ActionHold Action = "hold"
// ActionPan pans the camera smoothly to a target object or fixed coordinates.
ActionPan Action = "pan"
// ActionFollow continuously tracks a target object with the camera.
ActionFollow Action = "follow"
// ActionWalk moves an actor between coordinates over the clip's duration.
ActionWalk Action = "walk"
// ActionState plays a named animation state on an actor while holding its position.
ActionState Action = "state"
// ActionDrop drops an actor vertically from one coordinate to another.
ActionDrop Action = "drop"
// ActionPatrol moves an actor back and forth between two coordinates.
ActionPatrol Action = "patrol"
)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 and camera pans: "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") or actor track ("walk", "state", "drop", "patrol").
Action Action `yaml:"action,omitempty" schema:"enum=hold|pan|follow|walk|state|drop|patrol"`
// Target is the scene object ID a camera clip holds on, pans to or follows.
Target string `yaml:"target,omitempty"`
// FromX is the optional starting X coordinate for a camera pan or an actor walk, drop or patrol clip.
FromX *float32 `yaml:"fromX,omitempty"`
// FromY is the optional starting Y coordinate for a camera pan or an actor walk, drop or patrol clip.
FromY *float32 `yaml:"fromY,omitempty"`
// ToX is the destination X coordinate for a camera hold/pan or an actor walk, drop or patrol clip.
ToX *float32 `yaml:"toX,omitempty"`
// ToY is the destination Y coordinate for a camera hold/pan or an actor walk, drop or patrol clip.
ToY *float32 `yaml:"toY,omitempty"`
// OffsetX is an optional horizontal camera offset applied when holding on, panning to or following a target object.
OffsetX float32 `yaml:"offsetX,omitempty"`
// OffsetY is an optional vertical camera offset applied when holding on, panning to or following a target object.
OffsetY float32 `yaml:"offsetY,omitempty"`
// Zoom is the optional target camera zoom factor (positive) on a camera clip.
Zoom *float32 `yaml:"zoom,omitempty" schema:"exclusiveMinimum=0"`
// State is the animation state name played by an actor clip (required for "state" clips, optional for "walk", "drop" and "patrol").
State string `yaml:"state,omitempty"`
// Speed is the optional travel speed in world units per second for an 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"`
}Clip is one timed action or cue on a cutscene timeline track.
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"`
// 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://game.nsgo.dev/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(data []byte) (Cutscene, error)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].
func (c Cutscene) EffectiveKind() KindEffectiveKind reports whether c is a video cutscene or a timeline cutscene.
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 time.DurationDuration is a time.Duration written in a cutscene file as Go writes durations, such as "1.5s" or "250ms".
func (d Duration) MarshalYAML() (any, error)MarshalYAML writes d as time.Duration.String does.
func (d *Duration) UnmarshalYAML(n *yaml.Node) errorUnmarshalYAML reads a duration time.ParseDuration takes, refusing any other value.
type Easing stringEasing 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"
)func (e Easing) At(u float64) float64At evaluates e at normalized progress u in [0, 1].
type Fit stringFit 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 stringKind selects whether a cutscene plays a video or an in-engine timeline.
const (
// KindVideo plays a pre-rendered video over the game view through core.Video.
KindVideo Kind = "video"
// KindTimeline runs camera, actor, dialogue, sound and music tracks against a scene on game.Loop's fixed steps.
KindTimeline Kind = "timeline"
)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 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.
func NewPlayer(cx *core.Scope, opts Options) *PlayerNewPlayer 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 (p *Player) CanSkip() boolCanSkip 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 (p *Player) Dialogue() DialogueLineDialogue 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 (p *Player) Play(c Cutscene, done func(Result)) errorPlay 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 (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 (p *Player) Playing() boolPlaying reports whether a cutscene plays. Read in a computation, it subscribes it to changes, as a core.Signal does.
func (p *Player) Scene(c Cutscene, done func(Result)) (*scene.Controller, error)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 (p *Player) Skip() boolSkip 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 (p *Player) Step(dt time.Duration)Step advances an active timeline cutscene by dt on game.Loop's fixed Update step. Does nothing when no timeline cutscene is playing.
func (p *Player) Stop() boolStop ends the cutscene playing with Stopped, skippable or not, and reports whether one played.
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.
func (p *Player) View() core.NodeView is the cutscene playing, over the whole of the view it is in, and nothing while none plays. Mount it once, over the game's view.
type Reason uint8Reason 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
)func (r Reason) String() stringString names a reason for logs and diagnostics.
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 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(c Cutscene, target TimelineTarget) (*TimelinePlayer, error)NewTimelinePlayer validates c as a timeline cutscene, resolves its scene objects against target.Scene or target.Doc (when provided), snapshots initial poses and returns a player positioned at time 0.
func (p *TimelinePlayer) ActiveDialogue() DialogueLineActiveDialogue returns the dialogue line active at the current position.
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 (p *TimelinePlayer) ActorState(actorID string) stringActorState returns the active animation state of actorID, or "" when none is active.
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 (p *TimelinePlayer) CanSkip() boolCanSkip reports whether the cutscene is currently playing and can be skipped now.
func (p *TimelinePlayer) Cutscene() CutsceneCutscene returns the cutscene definition p plays.
func (p *TimelinePlayer) Done() boolDone reports whether playback has ended (finished, skipped or stopped).
func (p *TimelinePlayer) Length() time.DurationLength returns the cutscene's total duration.
func (p *TimelinePlayer) Pause()Pause pauses playback at the current position without ending the cutscene.
func (p *TimelinePlayer) Play()Play starts or resumes playback from the current position. A finished cutscene stays finished until Reset is called.
func (p *TimelinePlayer) Playing() boolPlaying reports whether playback is active.
func (p *TimelinePlayer) Reset()Reset rewinds to time 0, restores initial actor and camera poses, stops active cutscene music and clears done state.
func (p *TimelinePlayer) Seek(at time.Duration)Seek jumps directly to timestamp at (clamped to [0, Length]) and applies all actor, camera and dialogue states deterministically without firing sound, music or completion callbacks.
func (p *TimelinePlayer) Skip() boolSkip ends playback with Skipped if the cutscene is playing and CanSkip reports true.
func (p *TimelinePlayer) Stop() boolStop ends playback with Stopped regardless of Skippable, reporting whether the cutscene was active (playing or paused mid-cutscene).
func (p *TimelinePlayer) Time() time.DurationTime returns the current playback position in [0, Length].
func (p *TimelinePlayer) Update(dt time.Duration)Update advances a playing timeline cutscene by dt on a fixed game.Loop step.
type TimelineTarget struct {
// Scene, when non-nil, is the built 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
// Doc, when non-nil and Scene is 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
// 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)
// OnDone is called once when the cutscene finishes, is skipped or is stopped.
OnDone func(Result)
}TimelineTarget connects a TimelinePlayer to a scene, localization catalog, audio callbacks and mixer.
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's clips drive: "camera", "actor", "dialogue", "sound" or "music".
Kind TrackKind `yaml:"kind" schema:"required,enum=camera|actor|dialogue|sound|music"`
// Target is the scene object ID an actor track drives; required for "actor" tracks and omitted on other track kinds.
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.
Clips []Clip `yaml:"clips,omitempty"`
}Track is one lane on a timeline cutscene (camera, actor, dialogue, sound or music) holding timed clips.
type TrackKind stringTrackKind 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"
)