Game Development Reference
In-Depth Information
Check if the next frame's time is less than unloopedCurrentTime . This means it has
to pick the next frame, otherwise use the same frame to set the DOF of the bone.
if ( nextKey.time <= unloopedCurrentTime ) {
The currentTime value will always be equal to unloopedCurrentTime , but when
the animation has run its complete cycle once, then the unloopedCurrentTime
value will be greater than one and currentTime will be less than it. This means the
animation was run once. So, we have to pick the next frame only when this.loop is
valid, otherwise we have to stop the animation.
if ( currentTime < unloopedCurrentTime ) {
If the loop is valid, then pick the first frame and second frame to set the prevKey and
nextKey variables and loop until we do not find the correct nextKey , whose time is
less than the current time. Stop the animation if looping is not enabled.
if ( this.loop ) {
prevKey = this.data.hierarchy[ h ].keys[ 0 ];
nextKey = this.getNextKeyWith( type, h, 1 );
while( nextKey.time < currentTime ) {
prevKey = nextKey;
nextKey = this.getNextKeyWith( type, h,
nextKey.index + 1 );
}
} else {
this.stop();
return;
}
} else {
If currentTime equals unloopedCurrentTime , then the animation has not
completed once. Simply iterate over all keys until the value of currentTime is less
than that of nextKey . This will give us our new next and previous keys as shown in
the following code snippet:
do {
prevKey = nextKey;
nextKey = this.getNextKeyWith( type, h,
nextKey.index + 1 );
} while( nextKey.time < currentTime )
}
Set the new prevKey and nextKey values to the animation cache.
animationCache.prevKey[ type ] = prevKey;
animationCache.nextKey[ type ] = nextKey;
}
 
Search WWH ::




Custom Search