title: Simple Animation in Cocoa Objective-C
body: <p>I have written a simple animation for an iOS game and I am trying to convert it for Mac OS.</p>
  
  <p>Here is my code for iOS</p>
  
  <pre><code>NSMutableArray *imgArr = [[[NSMutableArray alloc] init] autorelease];
  
      for(int i = 1; i &lt; 6 + 1; i++) {
          [imgArr addObject: [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png", filePrefix, i]]];
      }
  
      UIImageView * animation = [[UIImageView alloc] initWithFrame:rect];
      animation.animationImages = imgArr;
  
      animation.animationRepeatCount = 1;
      [animation startAnimating];
  
      [self.view addSubview:animation];
  </code></pre>
  
  <p>As for cocoa, this part gives errors.. How can I fix this?</p>
  
  <pre><code>//animation.animationImages = imgArr;
  
  //animation.animationRepeatCount = 1;
  //[animation startAnimating];
  </code></pre>
  
  <p>New code with timer</p>
  
  <pre><code>for(int i = 0; i &lt; 6; i++)
      [NSTimer scheduledTimerWithTimeInterval:1
                                       target:self
                                     selector:@selector(anim)
                                     userInfo:nil
                                      repeats:NO];
  
  
  - (void)anim {
      ++num;
  
  
      NSImageView *animation = [[NSImageView alloc] initWithFrame:NSMakeRect(shipPosition.x, shipPosition.y, shipSize.width, shipSize.height)];
  
      [animation setImage: [NSImage imageNamed:[NSString stringWithFormat:@"explosprite%d.png", num]] ];
      [objectView addSubview:animation];
  
      [animation release];
  }
  </code></pre>