Showing UIAlertView on cocos2d Scene/Layer
This can be done easily just like when you are working with the standard ViewController.
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"My Title"];
[alert setMessage:@"My message"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert show];
[alert release];
With this, you can detect which button was pressed by handling the alertView message like this.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
}
else if (buttonIndex == 1)
{
// No
}
}
And when I do this in my game, I’ll pause the game first and resume when player pushed on the button. This can be done easily via sharedDirector as well.
[[Director sharedDirector] pause]; //Pause your game
[[Director sharedDirector] resume]; //Resume your game
Hope you enjoy!