AnimLength ( entity )

Parameters

entity - entity handle

Description

Returns the length of the sequence an entity is currently playing, in animation frames.

Pair it with AnimTime to work out progress through a move: AnimTime(e)/AnimLength(e) gives a 0 to 1 figure you can use to time a sound, a particle burst or a state change. It is also what you need to pick a playback speed that makes a move take a fixed length of time regardless of how many frames the artist gave it.

The value reflects the current sequence, so it changes when you switch sequences with Animate, PlayAnim or CrossFadeAnim.

An entity with no animation returns -1.

See also: AnimTime, AnimSeq, Animate, AddAnimSeq, Animating.

Example

; AnimLength Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
RotateEntity camera,12,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A grassy paddock for the fox to roam
ground=CreatePlane()
EntityTexture ground,LoadTexture("media/MossyGround.BMP")

; Load the rigged fox; it has the named clips "Survey", "Walk" and "Run"
fox=LoadAnimMesh("../../../samples/glTF/assets/Fox/Fox.glb")
If fox=0 Then RuntimeError "Could not load Fox.glb: "+ModelLoadError()

; Shrink the fox to game scale (the file is modelled about 100 units tall)
FitMesh fox,-0.8,0,-0.8,1.6,1.6,1.6,True

; Look up the sequence numbers of the named clips
survey=FindAnimSeq(fox,"Survey")
walk=FindAnimSeq(fox,"Walk")
run=FindAnimSeq(fox,"Run")

; Start the fox looking around
CrossFadeAnim fox,survey,0,1
clip$="Survey"

While Not KeyDown(1)

    ; Switch clips; AnimLength always reports the current sequence's length
    If KeyHit(2) Then CrossFadeAnim fox,survey,10,1 : clip$="Survey"
    If KeyHit(3) Then CrossFadeAnim fox,walk,10,1 : clip$="Walk"
    If KeyHit(4) Then CrossFadeAnim fox,run,10,1 : clip$="Run"

    UpdateWorld

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"1/2/3: play Survey/Walk/Run   Arrows: camera   Esc: exit"
    ; The length of the current animation sequence, in ticks
    Text 0,20,clip$+" sequence length: AnimLength(fox) = "+AnimLength(fox)
    Text 0,40,"AnimTime: "+AnimTime(fox)

    Flip

Wend

End

Index