PendingAnimEvents ( entity )
Parameters
| entity - handle of an animated entity |
Description
|
Returns how many animation events are waiting to be read from an entity. Events queue up during UpdateWorld and stay there until you take them out with PollAnimEvent, so the natural pattern is a small loop straight after your update: While PendingAnimEvents(player)>0 : e$=PollAnimEvent(player) : ... : Wend That drains the queue every frame and keeps the events in the order they fired. You can equally loop until PollAnimEvent returns an empty string; the count is just clearer to read, and useful if you want to know whether anything happened before committing to handling it. A single update can queue more than one event - a fast animation may cross two marks, and a looping clip can lap - so always drain in a loop rather than polling once per frame. See also: PollAnimEvent, AddAnimEvent, ClearAnimEvents, UpdateWorld. |
Example
; PendingAnimEvents 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 last_event$="none yet" While Not KeyDown(1) UpdateWorld ; We deliberately do NOT poll every frame, so you can watch the FIFO ; queue fill up as the fox keeps walking. Space polls the oldest event. If KeyHit(57) Then last_event$=PollAnimEvent(fox) ; 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: poll the oldest event Arrows: camera Esc: exit" ; The number of event names waiting in the entity's queue Text 0,20,"PendingAnimEvents(fox) = "+PendingAnimEvents(fox) Text 0,40,"Last polled: "+last_event$ Flip Wend End
Index