|
entity - handle of an animated entity sequence (optional) - sequence to clear, or -1 for all of them; -1 (default) |
|
Removes animation events from an entity, along with any that are still waiting to be read. Pass a sequence number to strip the events from that one move - handy when you rebuild a footstep pattern after changing a walk cycle. Leave the parameter off, or pass -1, and every event definition on the entity goes, together with the whole pending queue. The queue matters as much as the definitions. If a character dies mid-stride you probably do not want the footstep that was already queued to play a moment later; clearing the events throws away anything that has fired but not yet been polled. It is also worth doing when you recycle an entity from a pool, so events set up for its previous life do not leak into the next one. Passing a sequence number that does not exist raises an error. See also: AddAnimEvent, PollAnimEvent, PendingAnimEvents, Animate. |
; ClearAnimEvents 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
; Place footstep events on the walk cycle for UpdateWorld to queue
walk=FindAnimSeq(fox,"Walk")
AddAnimEvent fox,walk,10,"left footstep"
AddAnimEvent fox,walk,30,"right footstep"
CrossFadeAnim fox,walk,0,1
events_on=True
last_event$="none yet"
total=0
While Not KeyDown(1)
; Space toggles the footstep events on and off. ClearAnimEvents removes
; both the event definitions and anything still waiting in the queue.
If KeyHit(57)
events_on=1-events_on
If events_on
AddAnimEvent fox,walk,10,"left footstep"
AddAnimEvent fox,walk,30,"right footstep"
Else
ClearAnimEvents fox,walk
EndIf
EndIf
UpdateWorld
; Poll whatever UpdateWorld queued this frame
Repeat
event$=PollAnimEvent(fox)
If event$<>"" Then last_event$=event$ : total=total+1
Until event$=""
; 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,"Space: toggle events Arrows: camera Esc: exit"
If events_on Then Text 0,20,"Footstep events active (Space calls ClearAnimEvents)" Else Text 0,20,"ClearAnimEvents removed the events - no more footsteps"
Text 0,40,"Last event: "+last_event$+" total polled: "+total
Flip
Wend
End