Scrolling Text Algorithm for a Screen Saver

  • Hi,

    I'm working on a screen saver. It involves scrolling text across the
    screen. I'm using the simplest algorithm I could  think of: calls to
    NSString drawAtPoint:withAttributes: with the point moving a fixed
    offset at each call to animateOneFrame. This works Ok at low scrolling
    speeds, but at higher speeds (i.e. a larger offset), the motion
    appears jerky.

    I'm working on improving my code to minimize the amount of computation
    in animateOneFrame. However, if anyone can suggest a better algorithm
    for scrolling text, I'd appreciate it.
    --

    --
    Doug Fort, Consulting Programmer
    http://www.dougfort.com
  • On 30 Oct 2006, at 09:34, Doug Fort wrote:

    > Hi,
    >
    > I'm working on a screen saver. It involves scrolling text across the
    > screen. I'm using the simplest algorithm I could  think of: calls to
    > NSString drawAtPoint:withAttributes: with the point moving a fixed
    > offset at each call to animateOneFrame. This works Ok at low scrolling
    > speeds, but at higher speeds (i.e. a larger offset), the motion
    > appears jerky.
    >
    > I'm working on improving my code to minimize the amount of computation
    > in animateOneFrame. However, if anyone can suggest a better algorithm
    > for scrolling text, I'd appreciate it.

    Using NSString's drawing methods will be inefficient because it will
    re-do the text layout every time.  You should probably look at using
    the Cocoa Text system's NSLayoutManager object to do the layout once
    and then you can render the string over and over again with much
    lower overhead.

    An alternative to that might be to render it once into a bitmap, and
    scroll the bitmap across the display instead.  That approach would
    also mean you could use OpenGL if you wanted rather than Quartz.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
  • On Oct 30, 2006, at 6:26 AM, Alastair Houghton wrote:

    > On 30 Oct 2006, at 09:34, Doug Fort wrote:
    >
    >> I'm working on a screen saver. It involves scrolling text across the
    >> screen. I'm using the simplest algorithm I could  think of: calls to
    >> NSString drawAtPoint:withAttributes: with the point moving a fixed
    >> offset at each call to animateOneFrame. This works Ok at low
    >> scrolling
    >> speeds, but at higher speeds (i.e. a larger offset), the motion
    >> appears jerky.
    >>
    >> I'm working on improving my code to minimize the amount of
    >> computation
    >> in animateOneFrame. However, if anyone can suggest a better algorithm
    >> for scrolling text, I'd appreciate it.
    >
    > Using NSString's drawing methods will be inefficient because it
    > will re-do the text layout every time.  You should probably look at
    > using the Cocoa Text system's NSLayoutManager object to do the
    > layout once and then you can render the string over and over again
    > with much lower overhead.
    >
    > An alternative to that might be to render it once into a bitmap,
    > and scroll the bitmap across the display instead.  That approach
    > would also mean you could use OpenGL if you wanted rather than Quartz.

    And you can get really fancy by adding in motion blur (depending upon
    the speed of the scrolling).  I haven't done this myself, but I
    believe this is doable via CoreImage.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • If you want to support just 10.4, this seems like a perfect
    opportunity to use Quartz Composer to me.

    Mike.

    On 30 Oct 2006, at 09:34, Doug Fort wrote:

    > Hi,
    >
    > I'm working on a screen saver. It involves scrolling text across the
    > screen. I'm using the simplest algorithm I could  think of: calls to
    > NSString drawAtPoint:withAttributes: with the point moving a fixed
    > offset at each call to animateOneFrame. This works Ok at low scrolling
    > speeds, but at higher speeds (i.e. a larger offset), the motion
    > appears jerky.
    >
    > I'm working on improving my code to minimize the amount of computation
    > in animateOneFrame. However, if anyone can suggest a better algorithm
    > for scrolling text, I'd appreciate it.
    > --
    >
    > --
    > Doug Fort, Consulting Programmer
    > http://www.dougfort.com
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/mike.abdullah%
    > 40gmail.com
    >
    > This email sent to <mike.abdullah...>
  • On Oct 30, 2006, at 6:14 PM, Mike Abdullah wrote:

    > If you want to support just 10.4, this seems like a perfect
    > opportunity to use Quartz Composer to me.
    >
    > Mike.
    >
    > On 30 Oct 2006, at 09:34, Doug Fort wrote:
    >
    >> Hi,
    >>
    >> I'm working on a screen saver. It involves scrolling text across the
    >> screen. I'm using the simplest algorithm I could  think of: calls to
    >> NSString drawAtPoint:withAttributes: with the point moving a fixed
    >> offset at each call to animateOneFrame. This works Ok at low
    >> scrolling
    >> speeds, but at higher speeds (i.e. a larger offset), the motion
    >> appears jerky.
    >>
    >> I'm working on improving my code to minimize the amount of
    >> computation
    >> in animateOneFrame. However, if anyone can suggest a better algorithm
    >> for scrolling text, I'd appreciate it.

    Text drawing with NSString is a nightmare from:

    - a performance point of view

    - a buggy point of view (there are bugs in the API which prevents
    drawing the strings in some cases (borders for instance)).

    when it comes to screen savers.

    It may be a good idea to go with a OpenGL solution such as FreeType.
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today