Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I am making a death animation for a game. enemy1 is a UIImageView, and what I'm doing is when an integer is less than or equal to zero, it calls this deathAnimation which only happens once. What I want to do is use a CGPointMake right when the animation is finished being called. Note that before the deathAnimation is called, there is another animation that is constantly being called 30 times a second. I'm not using anything like cocos2d.

if (enemy1health <= 0) {
    [self slime1DeathAnimation];
    //How can i detect the end of this animation
}

This is how the animation is done:

-(void)slime1DeathAnimation{
    enemy1.animationImages = [[NSArray alloc] initWithObjects: 
                              [UIImage imageNamed:@"Slime Death 1.png"],
                              [UIImage imageNamed:@"Slime Death 2.png"],
                              [UIImage imageNamed:@"Slime Death 3.png"],
                              [UIImage imageNamed:@"Slime Death 4.png"],
                              [UIImage imageNamed:@"Slime Death 5.png"],
                              nil];
    enemy1.animationDuration = 0.5;
    enemy1.animationRepeatCount = 1;
    [enemy1 startAnimating];
}

If you need more code just ask

share|improve this question
add comment

3 Answers

Use +animateWithDuration:animations:completion: (available on iOS 4+), you will have a completion block. Something like :

[UIVIew animateWithDuration:0.5
animations:^{
enemy1.animationImages = [[NSArray alloc] initWithObjects: 
                              [UIImage imageNamed:@"Slime Death 1.png"],
                              [UIImage imageNamed:@"Slime Death 2.png"],
                              [UIImage imageNamed:@"Slime Death 3.png"],
                              [UIImage imageNamed:@"Slime Death 4.png"],
                              [UIImage imageNamed:@"Slime Death 5.png"],
                              nil];
}
completion: ^(BOOL finished){
   // Your animation is finished
}];

Hope this help.

share|improve this answer
add comment

In your case the best way to go would be to set the animationDuration and animationRepeatCount property of the UIImageView and then schedule a timer to call a selector method just after calling startAnimating with the same delay as the duration of animation.

enemy1.animationDuration = 0.5;
enemy1.animationRepeatCount = 1;
[enemy1 startAnimating];
[NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(somemethod) userInfo:nil repeats:NO];

Also you can stop the animation for the enemy1 object in that somemethod.

share|improve this answer
add comment

If you are animating the views using CoreAnimation, then you can set a method as callback that will be invoked after the animation is over using the following method:

[+ (void)setAnimationDidStopSelector:(SEL)selector][1]

More details on how the animation is done could help to answer your question right.

share|improve this answer
    
i've edited the post –  Will Feb 27 '12 at 16:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.