Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kamy

macrumors member
Original poster
Hi guys,

Am back with more drawing fun!

So am drawing images and animating them on an NsView which is on a
Window.

Here is what i do
Code:
    - (void)drawRect:(NSRect)rect
    {
            [self animateFrame:rect];
    }

In the animateFrame method - i do
a) Set background image
b) Do the animations

Code:
- (void)animateFrame: (CGRect) rect
{
              //backgroundImage is NSImage
               [backgroundImage drawInRect:rect
                                   fromRect:NSMakeRect(0, 0,    
                                   backgroundImage.size.width, 
                                   backgroundImage.size.height)
                                  operation:NSCompositeCopy
                                   fraction:1.0f];

               //Do more crazy animations
           
}

So far so good.
But i feel i can draw the background image only once instead of doing it every 0.2 seconds - Just to optimise things.

So when i take that line out and place it somewhere else. It draws the background for the first time and when 'drawRect' is fired again by timer - The background is gone - am assuming repainted.

So my question is - Is there a way to preserve the background drawing even as drawRect is invoked repeatedly?

Am scrounging through the Apple docs but i though i will ask the Guru's here!

Thanks!
KamyFC
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.