Game Development Reference
In-Depth Information
Listing 15-1 . A UIAlertViewIs Created and Shown over cocos2d's View (CCGLView
-(void) showAlertView
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"UIAlertView Example"
message:@"Hello Cocoa Touch!"
otherButtonTitles:@"Done", nil];
[alertView show];
Tip It's not necessary to add a UIAlertView to another view. This makes it
very straightforward to create UIAlertView messages. The only drawback is
that UIAlertView will always be drawn above everything else and will swal-
low all touches as long as it's displayed. No amount of sending views to back or
reordering the view hierarchy will change that. If you need a simple solution for
a pause menu, UIAlertView is your cheap and dirty friend, especially during
development. But keep in mind that while touches are disabled, you'll still be
receiving acceleration events, which you'll have to turn off or ignore while the
UIAlertView is shown.
The HelloWorldLayer class will receive all events from the UIAlertView and
can respond to them by simply implementing one or more of the UIAler-
tViewDelegate methods. For this example, I decided to respond to the didDis-
missWithButtonIndex message (see Listing 15-2 ), which is sent whenever the
user taps a button, which always dismisses the UIAlertView regardless of which
button was tapped. Another CCLabelTTF , with a string and color that depend on the
buttonIndex , is added to the cocos2d scene at a random position every time the
alert view is dismissed.
Listing 15-2 . Responding to the UIAlertView didDismissWithButtonIndex Message
Search Nedrilad ::

Custom Search