SetAnimKey entity,frame[,pos_key][,rot_key][,scale_key]
Parameters
|
entity - entity handle frame - frame number to store the key at pos_key (optional) - True to record the entity position; True (default) rot_key (optional) - True to record the entity rotation; True (default) scale_key (optional) - True to record the entity scale; True (default) |
Description
|
Records the current position, rotation and scale of an entity as an animation key at the given frame. This is how you build animation in code rather than in a modelling package. Put the entity where you want it with PositionEntity, RotateEntity and ScaleEntity, call SetAnimKey to pin that pose to a frame number, move it somewhere else, pin another frame, and so on. The engine fills in everything between the keys for you. Once the keys are in place, call AddAnimSeq to turn them into a playable sequence, then Animate to run it. Typical uses are lifts, patrolling platforms, swinging doors, camera fly-throughs and cut-scene moves - anything on rails that you would rather describe in code than export from a modeller. The three optional flags let you record only part of the pose. Passing 0 for scale_key, for instance, keys position and rotation but leaves scale out of the animation, so an entity you resize at runtime keeps its size while the move plays. Keys apply to the entity you name, so an assembly made of several entities needs keys set on each part. Frames are numbered from 0, and the sequence you build with AddAnimSeq must be long enough to reach your highest frame. See also: AddAnimSeq, Animate, AnimLength, PositionEntity, RotateEntity. |
Example
; SetAnimKey Example ; ------------------ Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,3,-10 light=CreateLight() RotateEntity light,45,45,0 ground=CreatePlane() EntityTexture ground,LoadTexture("media/MossyGround.BMP") ; A bouncing beach ball to animate ball=CreateSphere(16) EntityColor ball,255,60,60 ; Record the bounce: position the ball along an arc and store one ; animation key per frame with SetAnimKey For frame=0 To 40 x#=frame*0.2-4 y#=Abs(Sin(frame*18))*3+0.5 PositionEntity ball,x,y,0 SetAnimKey ball,frame Next ; Bake the recorded keys into a playable sequence seq=AddAnimSeq(ball,40) ; Play the recording back ping-pong, so the ball bounces there and back Animate ball,2,0.5,seq While Not KeyDown(1) 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,"Arrows: camera Esc: exit" Text 0,20,"SetAnimKey recorded 41 keys, now playing back AnimTime: "+AnimTime(ball) Flip Wend End
Index