1
\$\begingroup\$

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

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ i've edited the post \$\endgroup\$
    – Will
    Feb 27, 2012 at 16:32
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ This code is doing nothing! \$\endgroup\$ Jan 12, 2015 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .