Hi,
Here is my code for making a bat flap its wings and respond to touches.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"Bat1.png"],
[UIImage imageNamed:@"Bat2.png"],
[UIImage imageNamed:@"Bat3.png"],
[UIImage imageNamed:@"Bat2.png"],
[UIImage imageNamed:@"Bat1.png"],
[UIImage imageNamed:@"Bat4.png"],
[UIImage imageNamed:@"Bat5.png"],
[UIImage imageNamed:@"Bat6.png"],
[UIImage imageNamed:@"Bat5.png"],
[UIImage imageNamed:@"Bat4.png"],
nil];
UIImageView * batView = [[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, 80, 56)];
batView.animationImages = imageArray;
batView.animationDuration = 0.70;
[follower1 addSubview:batView];
[batView startAnimating];
[UIImageView beginAnimations:@"follow" context:nil];
[UIImageView setAnimationDuration:1];
[UIImageView setAnimationBeginsFromCurrentState:YES];
UITouch *touch = [touches anyObject];
follower1.center = [touch locationInView:self];
[UIImageView commitAnimations];
[batView release];
}
The problem is that after the second touch the animations overlap on top of each other so after every touch it looks like there are lots of bats underneath!
Any help will be much appreciated!
Thank You!