diff options
Diffstat (limited to 'Classes/RootViewController.m')
-rwxr-xr-x | Classes/RootViewController.m | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/Classes/RootViewController.m b/Classes/RootViewController.m new file mode 100755 index 0000000..edd67cb --- /dev/null +++ b/Classes/RootViewController.m | |||
@@ -0,0 +1,152 @@ | |||
1 | // | ||
2 | // RootViewController.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | // | ||
10 | // RootViewController + iAd | ||
11 | // If you want to support iAd, use this class as the controller of your iAd | ||
12 | // | ||
13 | |||
14 | #import "cocos2d.h" | ||
15 | |||
16 | #import "RootViewController.h" | ||
17 | #import "GameConfig.h" | ||
18 | |||
19 | @implementation RootViewController | ||
20 | |||
21 | /* | ||
22 | // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. | ||
23 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | ||
24 | if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { | ||
25 | // Custom initialization | ||
26 | } | ||
27 | return self; | ||
28 | } | ||
29 | */ | ||
30 | |||
31 | /* | ||
32 | // Implement loadView to create a view hierarchy programmatically, without using a nib. | ||
33 | - (void)loadView { | ||
34 | } | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | ||
39 | - (void)viewDidLoad { | ||
40 | [super viewDidLoad]; | ||
41 | } | ||
42 | */ | ||
43 | |||
44 | |||
45 | // Override to allow orientations other than the default portrait orientation. | ||
46 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
47 | |||
48 | // | ||
49 | // There are 2 ways to support auto-rotation: | ||
50 | // - The OpenGL / cocos2d way | ||
51 | // - Faster, but doesn't rotate the UIKit objects | ||
52 | // - The ViewController way | ||
53 | // - A bit slower, but the UiKit objects are placed in the right place | ||
54 | // | ||
55 | |||
56 | #if GAME_AUTOROTATION==kGameAutorotationNone | ||
57 | // | ||
58 | // EAGLView won't be autorotated. | ||
59 | // Since this method should return YES in at least 1 orientation, | ||
60 | // we return YES only in the Portrait orientation | ||
61 | // | ||
62 | return ( interfaceOrientation == kCCDeviceOrientationLandscapeLeft ); | ||
63 | |||
64 | #elif GAME_AUTOROTATION==kGameAutorotationCCDirector | ||
65 | // | ||
66 | // EAGLView will be rotated by cocos2d | ||
67 | // | ||
68 | // Sample: Autorotate only in landscape mode | ||
69 | // | ||
70 | if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { | ||
71 | [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; | ||
72 | } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { | ||
73 | [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; | ||
74 | } | ||
75 | |||
76 | // Since this method should return YES in at least 1 orientation, | ||
77 | // we return YES only in the Portrait orientation | ||
78 | return ( interfaceOrientation == UIInterfaceOrientationPortrait ); | ||
79 | |||
80 | #elif GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
81 | // | ||
82 | // EAGLView will be rotated by the UIViewController | ||
83 | // | ||
84 | // Sample: Autorotate only in landscpe mode | ||
85 | // | ||
86 | // return YES for the supported orientations | ||
87 | |||
88 | return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); | ||
89 | |||
90 | #else | ||
91 | #error Unknown value in GAME_AUTOROTATION | ||
92 | |||
93 | #endif // GAME_AUTOROTATION | ||
94 | |||
95 | |||
96 | // Shold not happen | ||
97 | return NO; | ||
98 | } | ||
99 | |||
100 | // | ||
101 | // This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
102 | // | ||
103 | #if GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
104 | -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration | ||
105 | { | ||
106 | // | ||
107 | // Assuming that the main window has the size of the screen | ||
108 | // BUG: This won't work if the EAGLView is not fullscreen | ||
109 | /// | ||
110 | CGRect screenRect = [[UIScreen mainScreen] bounds]; | ||
111 | CGRect rect; | ||
112 | |||
113 | if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) | ||
114 | rect = screenRect; | ||
115 | |||
116 | else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) | ||
117 | rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width ); | ||
118 | |||
119 | CCDirector *director = [CCDirector sharedDirector]; | ||
120 | EAGLView *glView = [director openGLView]; | ||
121 | float contentScaleFactor = [director contentScaleFactor]; | ||
122 | |||
123 | if( contentScaleFactor != 1 ) { | ||
124 | rect.size.width *= contentScaleFactor; | ||
125 | rect.size.height *= contentScaleFactor; | ||
126 | } | ||
127 | glView.frame = rect; | ||
128 | } | ||
129 | #endif // GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
130 | |||
131 | |||
132 | - (void)didReceiveMemoryWarning { | ||
133 | // Releases the view if it doesn't have a superview. | ||
134 | [super didReceiveMemoryWarning]; | ||
135 | |||
136 | // Release any cached data, images, etc that aren't in use. | ||
137 | } | ||
138 | |||
139 | - (void)viewDidUnload { | ||
140 | [super viewDidUnload]; | ||
141 | // Release any retained subviews of the main view. | ||
142 | // e.g. self.myOutlet = nil; | ||
143 | } | ||
144 | |||
145 | |||
146 | - (void)dealloc { | ||
147 | [super dealloc]; | ||
148 | } | ||
149 | |||
150 | |||
151 | @end | ||
152 | |||