Game Development Reference
In-Depth Information
@interface HelloWorldLayer : CCLayer < UIAlertViewDelegate>
{
}
All other changes are made to the HelloWorldLayer.m implementation file. The
init method of the “Hello World” sample is modified to use a color gradient back-
ground, just so you see the visual effect of the UIAlertView darkening the screen,
and to call the showAlertView method.
-(id) init
{
if ((self = [super init]))
{
CCLayerGradient* layer = [CCLayerGradient layerWithColor:ccc4(100,150,255,255)
fadingTo:ccc4(255,200,50,100)
alongVector:ccp(0.75f, 0.25f)];
[self addChild:layer];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World"
fontName:@"Marker Felt"
fontSize:64];
CGSize size = [CCDirector sharedDirector].winSize;
label.position = ccp(size.width / 2, size.height / 2);
[self addChild:label];
self.isTouchEnabled = YES;
[self showAlertView];
}
return self;
}
The showAlertView method allocates a UIAlertView with a title, two buttons,
and the message text “Hello Cocoa Touch!” For a delegate, you'll be using self now
that you've added the UIAlertViewDelegate protocol to the HelloWorldLay-
er class.
Finally, you can show the alert view. Listing 15-1 shows the resulting code.
 
Search Nedrilad ::




Custom Search