domhofmann / PRTween

Lightweight tween library for iOS
BSD 2-Clause "Simplified" License
459 stars 63 forks source link

NSTimer continues running after all tweens have completed #35

Open jowie opened 11 years ago

jowie commented 11 years ago

I have tweaked my local copy so that it invalidates the timer once all tweens have finished, and creates a new timer if needed at the top of addTweenOperation: instead. I believe this is better for large projects such as mine, as it cuts down on the number of instructions happening every second:

- (PRTweenOperation*)addTweenOperation:(PRTweenOperation*)operation
{
    if (timer == nil)
    {
        timer = [NSTimer scheduledTimerWithTimeInterval:kPRTweenFramerate target:self selector:@selector(update) userInfo:nil repeats:YES];
    }
...

And again at the bottom of the update method:

...
    if(tweenOperations.count == 0)
    {
        [timer invalidate];
        timer = nil;
    }
}

Let me know if I can pull this and add the code, I would be happy to!