On 12/03/2010, at 5:23 AM, Michael A. Crawford wrote: > - (void)timerFireMethod:(NSTimer*)theTimer > { > #if 0 > // Here I was using a periodic timer to animate the scroll. I noticed that > // the animation wasn't smooth and then remembered that CA is supposed to > do > // the animating for me. So, I switched to trying the code below but that > // doesn't work either. I'm really just grasping at straws here. > static CGPoint origin = {0.0f, 0.0f}; > origin.x += 5.0f; > [scrollLayer scrollToPoint:origin]; > #else
Hi Michael, This is a classic "naive" mistake. You're incrementing the position by a fixed amount each time the timer fires. Problem is, you can't guarantee that the timer will fire exactly at the time it should, so your scrolling speed is at the mercy of how busy things are, so will speed up and slow down. Recall that speed is distance/time, so if you want a constant speed, you have to work out how much distance the thing should have moved in the actual time interval you got. Roughly (typed into mail): - (void) timerFireMethod:(NSTimer*) theTimer { NSTimeInterval elapsedTime = [NSDate timeIntervalSinceReferenceDate] - m_startTime; // m_startTime ivar set when the animation began CGFloat distance = m_speed * elapsedTime; // m_speed is the scrolling speed in points per second [thing setPosition:distance]; } With this approach, the exact timing intervals don't matter - the position will be correct. If things get busy what will happen is that the jumps between positions will get a bit larger. That said, Core Animation might do the job better, but I just wanted to point out what the problem was with your original approach. --Graham _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com