hello,
as Todd mentioned about unfulfilled promises to post code i felt guilty. here is the Animater class i use in karga to animate avatar movements. it coordinates animations deciding when to switch animation and during completion either rollback the animation or go till end. you cannot directly compile it but it will give an idea
say your avatar is walking forwards and you animate accordingly. then movement stopped but you're in the middle of walk animation, what will you do now ? leave the avatar as it is (one foot top) or play animation till end, or play it backwards ? what will you do when avatar decided to strafe left/right while he was walking forward ? how will you smootly switch between walk forward and strafe animation ? Animater class takes care of these. it does the low level dirty job..
the typical usage is as follows: this code piece is called every frame. seconds is passed seconds since last frame
// clamping mode is important here, as we dont want roundings at ends
Avatar.getAnimationSequence().setClampingMode(Animation.USE_CLAMPING);
if (moving) {
Animater.Frame frame = animater.getNext(step, seconds);
animate(frame.index, getSequenceNumber(frame.sequence));
} else {
if (animater.hasNext()) {
Animater.Frame frame = animater.getNext(seconds);
animate(frame.index, getSequenceNumber(frame.sequence));
}
}
Util3D.Step is an enum defining what step avatar makes during movement, one of:
NONE, FORWARD, BACKWARD, JUMP_UP, JUMP_FALL, FALL_DOWN,
LEFT, RIGHT, // strafe
TURN_LEFT, TURN_RIGHT, // turn around
FAST_FORWARD; // run
AvatarInfo.Animation stores information about animation sequences of avatar. the only relevant part used here is period, how long the sequence lasts. the enum Interval is the segments of animation sequences. as forum settings doesnt allow to post such a long piece of code i placed it in karga site
here is the
Animater classhope this helps
r a f t