Animation Player
Animation Player plays its Clip, from the start of Play when Play On Start is set. Speed scales time; a negative speed plays backwards. Loop overrides the loop mode of the clip.
In Try it, the runner plays the built-in run clip and the pendulum plays a separate bob clip. Press R to replay the runner or B to reverse it; their scripts show presentation and gameplay events.
| Method | |
|---|---|
Play(clip) |
start a clip from the beginning; nil plays the current clip again |
Stop() |
end the clip; restore tracks get their old values, Finished(-1) runs |
Pause(), Resume() |
hold and continue |
Seek(t) |
jump to a time in the clip without firing the events in between |
SetSpeed(s) |
change the speed |
| Signal | |
|---|---|
Finished(cycle int) |
a clip that does not loop ended (0), or Stop (-1) |
Event(id int, payload float) |
the clip reached an event |
Commands take effect on the next fixed step, so a script may call them from Update. Time, Playing and Cycle show the state during Play.
A track whose node is missing (ANM005) or whose property does not match its kind (ANM001) is off; the rest of the clip plays. When a clip is imported again with the same tracks, the players keep their place; with other tracks they stop (ANM008).
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Scene4 nodes
Scriptmain.aes
package demo
import (
"aego/anim"
"aego/debug"
"aego/input"
)
// Runner plays the built-in run clip; R plays it again, B reverses it.
script Runner {
var steps int
var dust float
func Update(dt float) {
a := node.Get<AnimationPlayer>()
if input.KeyPressed(input.KeyR) {
a.Play(nil)
}
if input.KeyPressed(input.KeyB) {
a.SetSpeed(-a.Speed)
}
p := node.WorldPosition()
if dust > 0 {
dust -= dt
debug.Rect(Rect{p.X - 0.5, p.Y + 0.45, dust * 4, 0.06}, Color{0.85, 0.85, 0.85, dust * 4})
}
debug.Text(Vec2{p.X - 2, p.Y - 1.4}, "R: replay B: reverse steps " + string(steps), Color{0.8, 0.8, 0.8, 1})
}
func OnAnimEvent(id int, payload float) {
if anim.EventName(id) == "Footstep" {
steps++
dust = 0.25
}
}
}
// Pendulum sways with the built-in bob clip; its gameplay event Hit lights the mark.
script Pendulum {
var flash float
func OnAnimEvent(id int, payload float) {
if anim.EventName(id) == "Hit" {
flash = payload
}
}
func Update(dt float) {
p := node.WorldPosition()
if flash > 0 {
flash -= dt * 2
}
debug.Rect(Rect{p.X - 0.25, p.Y - 0.6, 0.5, 0.2}, Color{1, 0.55, 0.3, 0.2 + flash})
debug.Text(Vec2{p.X - 1, p.Y - 1}, "Hit at the right turn", Color{0.8, 0.8, 0.8, 1})
}
}