| entity - entity handle |
|
Returns how far through its current sequence an entity is, measured in animation frames. The value is a float running from 0 to AnimLength(entity), and it moves in fractions of a frame because animation is interpolated. Divide by AnimLength to get a 0 to 1 progress figure - handy for driving a progress bar, or for firing a footstep sound at the exact point in a walk cycle. For sound and gameplay cues, though, AddAnimEvent is usually less fiddly than watching the clock. During a crossfade this reports the time in the incoming clip, which is the one you are blending towards. An entity with no animation returns -1, so treat a negative result as "not animated" rather than as a real time. See also: AnimLength, AnimSeq, Animating, Animate, AddAnimEvent. |
; AnimTime 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
; Start the fox walking in a loop
walk=FindAnimSeq(fox,"Walk")
CrossFadeAnim fox,walk,0,1
speed#=1
While Not KeyDown(1)
; Change the playback speed to see AnimTime advance faster or slower
If KeyDown(26) And speed>0.1 Then speed=speed-0.01 : SetAnimSpeed fox,speed
If KeyDown(27) And speed<4 Then speed=speed+0.01 : SetAnimSpeed fox,speed
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
; AnimTime reports where playback is within the current sequence
time#=AnimTime(fox)
length=AnimLength(fox)
Text 0,0,"[ / ]: change speed Arrows: camera Esc: exit"
Text 0,20,"AnimTime(fox) = "+time+" of "+length+" ticks"
; Draw the animation time as a progress bar
Color 80,200,80
Rect 0,40,time*200.0/length,10,True
Color 255,255,255
Rect 0,40,200,10,False
Flip
Wend
End