IFTTT/JazzHands

Duplicate frames generated between each pair of key frames

Closed this issue · 3 comments

I'm seeing what looked like rounding errors in the animations but turned out to be a duplicate frame generated between each pair of key frames. This code in IFTTTAnimation.m's addKeyFrame: iterates over all pairs of key frames and generates entries in the timeline.

 for (NSUInteger i = 0; i < self.keyFrames.count - 1; i++) {
    IFTTTAnimationKeyFrame *currentKeyFrame = [self.keyFrames objectAtIndex:i];
    IFTTTAnimationKeyFrame *nextKeyFrame = [self.keyFrames objectAtIndex:i+1];

    for (NSInteger j = currentKeyFrame.time; j <= nextKeyFrame.time; j++) {
        [self.timeline addObject:[self frameForTime:j startKeyFrame:currentKeyFrame endKeyFrame:nextKeyFrame]];
    }
}

If you follow the logic you will see that the final 'j' value in the inner loop ( nextKeyFrame.time) is the same as the first value (currentKeyFrame.time) for the next iteration of the outer loop. Changing the terminating condition for the inner loop to use < nextKeyFrame.time instead of <= will result in the final key frame not being generated, so that's not the right fix.

The simplest way (in my opinion) to avoid the duplicate is to begin all but the first iteration of the inner loop at currentKeyFrame.time+1:

for (NSInteger j = currentKeyFrame.time + (i == 0 ? 0 : 1); j <= nextKeyFrame.time; j++) {

An alternate would be stop the iteration of the inner loop one short except for the final outer loop iteration.

+1

Thanks! Hopefully resolved here b95aa34

Thanks for the quick fix.