-(void)checkCollision{
if (CGRectIntersectsRect(player.frame, enemy.frame)) {
[randomMain invalidate];
[start setHidden:NO];
CGRect frame = [player frame];
frame.origin.x = 137.0f;
frame.origin.y = 326.0;
[player setFrame:frame];
CGRect frame2 = [enemy frame];
frame2.origin.x = 137.0f;
frame2.origin.y = 20.0;
[enemy setFrame:frame2];
[randomMain invalidate];
[start setHidden:NO];
[timer invalidate];
time.text = @"0";
Hello There, the problem I am facing is that I try and make an alert view below yet i get an error saying the following: Invalid argument type “void” to unary expression. on the line reading: -(void) alert1:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {
Cheers
time.text = @"0";
[timer invalidate];
NSString *timemessage = [NSString stringWithFormat:@"Unlucky! You survived for %i seconds!", timenumber];
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"You've Been Caught!" message:timemessage delegate:nil cancelButtonTitle:@"Try Again" otherButtonTitles:@"Show Leaderboard", @"Submit To game Center",nil];
[alert1 show];
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {
if (ButtonIndex == 1) {
GKScore *myScore = [[GKScore alloc]
initWithCategory:@"*****"];
myScore.value = timenumber;
}
}
}}
;
The line
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)ButtonIndex {is a start of a new method. It can’t be enclosed insidecheckCollision. You need to move it and all of its code outside. It can go right after the end ofcheckCollisionif you want. You also need to set the delegate of the UIAlertView to the object you want to receive thealertView:clickedButtonAtIndex:callback. Usually that isself. Something like this: