-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuLayer.mm
75 lines (55 loc) · 1.53 KB
/
MenuLayer.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// MenuLayer.m
// brendan game
//
// Created by Francis Tseng on 12/1/13.
// Copyright 2013 Francis Tseng. All rights reserved.
//
#import "MenuLayer.h"
#import "GameLayer.h"
@interface MenuLayer()
-(void) createMenu;
@end
@implementation MenuLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
MenuLayer *layer = [MenuLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id) init
{
if( (self=[super init])) {
// enable events
self.touchEnabled = YES;
self.accelerometerEnabled = YES;
CGSize s = [CCDirector sharedDirector].winSize;
CCLabelTTF *label = [CCLabelTTF labelWithString:@"sup" fontName:@"Helvetica Neue" fontSize:32];
[label setColor:ccc3(255,255,255)];
label.position = ccp(s.width/2, s.height/2);
[self addChild:label z:0];
[self createMenu];
}
return self;
}
-(void) createMenu
{
// Default font size will be 22 points.
[CCMenuItemFont setFontSize:22];
[CCMenuItemFont setFontName:@"Helvetica Neue"];
// New Game Button
CCMenuItemLabel *newGame = [CCMenuItemFont itemWithString:@"New Game" block:^(id sender){
[[CCDirector sharedDirector] replaceScene: [GameLayer scene]];
}];
CCMenu *menu = [CCMenu menuWithItems: newGame, nil];
[menu alignItemsVertically];
CGSize size = [[CCDirector sharedDirector] winSize];
[menu setPosition:ccp( size.width/2, size.height/2 - 50)];
[self addChild: menu z:-1];
}
@end