• 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: Best way to animate series of images in 10.4
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to animate series of images in 10.4


  • Subject: Re: Best way to animate series of images in 10.4
  • From: Erik Buck <email@hidden>
  • Date: Thu, 17 Nov 2005 23:45:57 -0500

You can create an animation in a custom view in any of several ways. It doesn't matter if you tile the animation frames in one big image or keep them in separate NSImage (or NSBitmapImageRep) instances.

Just use an NSTimer or delayed perform to send your custom view - display messages. In your custom view's -drawRect: method, draw a different frame (or sub-image) each time.

here is one approach written in email:

@class MyView : NSView
{
  NSArray      *images;       // an array of NSImages
  int          frameIndex;    // current frame number in animation
}

- (IBAction)startAnimating:(id)sender;

@end

@implementation MyView

- (void)runStep:(id)sender
{
   [[self class] cancelPreviousPerformRequestsWithTarget:self
      selector:@selector(runStep:) object:nil];

   if(frameIndex < [images count])
   {
      // Schedule another call to this method in 1/20 second
      [self performSelector:@selector(runStep:) withObject:nil
         afterDelay:0.05f];

      [self display];
      frameIndex++;
   }
}


- (IBAction)startAnimating:(id)sender { [self runStep:nil]; return self; }

- (void)drawRect:(NSRect)aRect
{
   [[images objectAtIndex:frameIndex] compositeToPoint:NSZeroPoint
      operation: NSCompositeSourceOver];
}

@end


There is a little game including animation using NSImage instances at http://www.cocoaprogramming.net/Downloads.html


You might also like the book "Cocoa Programming". It is also available in an inexpensive electronic form if you like that: http:// www.amazon.com/gp/product/0672322307/104-2680927-9353525? v=glance&n=283155&v=glance


There are also several no-code solutions: - Create a Quicktime animation and display that in a QTView. - Create a GIF animation and display that in an NSImageView - Create a web animation and display that in a WebKit view.



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: NSImageView does not update on setNeedsDisplay
  • Next by Date: HOW TO GET SYTEM INFO THROUGH CARBON APPLICATION
  • Previous by thread: Re: Best way to animate series of images in 10.4
  • Next by thread: NSImageView does not update on setNeedsDisplay
  • Index(es):
    • Date
    • Thread