|
entity - handle of an animated entity speed# - animation frames advanced per UpdateWorld |
|
Changes the speed of the animation an entity is already playing, without restarting it. This is the command Animate cannot give you: Animate always jumps back to the first frame, so using it to change speed makes a walking character hitch. SetAnimSpeed leaves the entity exactly where it is in the sequence and only alters the rate, which is what you want when a walk needs to speed up into a jog, or when a machine winds up and down. The obvious use is tying playback to movement so feet do not skate: work out how fast the character is actually travelling and scale the animation speed to match. A speed of 0 pauses playback, freezing the entity on its current pose; passing a non-zero value later picks up from that pose. During a true crossfade, 0 also pauses the blend itself, so the two clips hold at their current mix rather than the blend running on to completion. A negative speed runs the animation backwards. The entity must have animation to work with - the command raises an error otherwise - and the speed must be a finite number. See also: AnimSpeed, Animate, PlayAnim, CrossFadeAnim, AnimTime. |
; SetAnimSpeed 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
paused=False
While Not KeyDown(1)
; SetAnimSpeed changes the speed live, without restarting the clip
If KeyDown(26) And speed>0.1 Then speed=speed-0.01
If KeyDown(27) And speed<4 Then speed=speed+0.01
; Space pauses with a speed of zero, and resumes where it left off
If KeyHit(57) Then paused=1-paused
If paused Then SetAnimSpeed fox,0 Else 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
Text 0,0,"[ / ]: change speed Space: pause/resume Arrows: camera Esc: exit"
If paused Then Text 0,20,"SetAnimSpeed fox,0 (paused)" Else Text 0,20,"SetAnimSpeed fox,"+speed
Text 0,40,"AnimTime: "+AnimTime(fox)
Flip
Wend
End