Animater: a class which can coordinate animation during unit movement

Started by raft, May 30, 2007, 05:28:01 AM

Previous topic - Next topic

raft

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 class

hope this helps  ;)
r a f t


ToddMcF2002

Nice code raft! First off - its so much cleaner than my meat and potatoes coding style with its just keep on going exception handling  ;D.

I never even considered reversing a sequence.  Nice concept!

Thanks for contributing too of course.  The more the merrier!


raft

thanks and you're welcome ;)
the code took that shape after several tries and trial and errors. mine was a piece of spagetti too at the beginning  ::)

cyberkilla

I can't remember what I was doing to mimic this :D I should really check.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG