• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Need help with scrolling marquee
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help with scrolling marquee


  • Subject: Re: Need help with scrolling marquee
  • From: "Michael A. Crawford" <email@hidden>
  • Date: Thu, 11 Mar 2010 17:17:50 -0500

Thanks, Graham, I realized the timer would have jitter.  When I realized what was going on and began to think about how to fix it, that is when I had one of those head-slap moments where I asked, "Why am I not using CoreAnimation for this?"

-Michael

On Mar 11, 2010, at 4:53 PM, Graham Cox wrote:

>
> 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 (email@hidden)

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:

This email sent to email@hidden

References: 
 >Need help with scrolling marquee (From: "Michael A. Crawford" <email@hidden>)
 >Re: Need help with scrolling marquee (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Need help with scrolling marquee
  • Next by Date: Re: Need help with scrolling marquee
  • Previous by thread: Re: Need help with scrolling marquee
  • Next by thread: Noob iPhone Question
  • Index(es):
    • Date
    • Thread