The following method creates a burst effect and plays an accompanying sound. The problem is that each smaller star image view is supposed to hide, as indicated in one of the lines of code, but none of them do. Edit: Thanks to the NSLog command in that code, I can see that each relevant image view's "hidden" property is set to YES.
Here's the method:
Please help me, and thanks!
Here's the method:
Code:
-(void)playBurstingStarAnimation
{
[[self stillStarImageView] setHidden:false];
float radius = 250;
__block NSInteger animsCompleted = 0;
for (UIImageView *starImageView in [self animatedStarImageViews])
{
[starImageView setHidden:false];
CGPoint stillStarCenter = [[self stillStarImageView] center];
CGPoint starCenter = [starImageView center];
CGPoint differencePoint = CGPointMake((starCenter.x - stillStarCenter.x), (starCenter.y - stillStarCenter.y));
CGFloat angle = atan2f(differencePoint.y, differencePoint.x);
CGFloat destinationX = (cosf(angle) * radius) + (stillStarCenter.x);
CGFloat destinationY = (sinf(angle) * radius) + (stillStarCenter.y);
CGPoint destination = CGPointMake(destinationX, destinationY);
[UIView animateWithDuration:3 animations:^{ [starImageView setCenter:destination]; } completion:^(BOOL finished){ animsCompleted = animsCompleted + 1; if (animsCompleted == [[self animatedStarImageViews] count]) { [starImageView setHidden:true]; NSLog(@"%@", [starImageView description]); [self performSelector:starAnimationCompleted]; }; }];
}
NSURL *burstSound = [[NSBundle mainBundle] URLForResource:@"burst" withExtension:@"mp3"];
AVPlayerItem *burstSoundItem = [AVPlayerItem playerItemWithURL:burstSound];
[[self queuePlayer] insertItem:burstSoundItem afterItem:nil];
[[self queuePlayer] play];
}
Please help me, and thanks!
Last edited: