Search code examples
iphoneiosobjective-cmacos2d-games

How to prevent UIImage from continually replaying an animation


I am making a game and currently my "player" is animating as I've implemented (which is wrong at the moment) and it continually runs the animation from start to start because it always restarts from the beginning when the function is called. What is the best way to prevent this and let the animation run all the way through? Here is the code I'm using at the moment:

- (void) startAnimatingLeft
{

NSArray *images = [NSArray arrayWithObjects:img9,img10,img11,img12,img13,img14,img15,img16, nil];

[imageView setAnimationImages:images];

[imageView startAnimating];
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(nothingMovingLeft) userInfo:nil repeats:NO];
}

Solution

  • From UIImage documentation:

    startAnimating

    This method always starts the animation from the first image in the list.

    So you shouldn't call this method if the image is already animating. You can call isAnimating method to check if image is animating.