-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
AppDelegate.m
executable file
·119 lines (99 loc) · 4.22 KB
/
AppDelegate.m
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* SpriteBuilder: http://www.spritebuilder.org
*
* Copyright (c) 2012 Zynga Inc.
* Copyright (c) 2013 Apportable Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "cocos2d.h"
#import "TestbedSetup.h"
#import "CCDirector_Private.h"
#import "MainMenu.h"
#import "CCPackageConstants.h"
#if __CC_METAL_SUPPORTED_AND_ENABLED
#import "CCMetalView.h"
#endif
@interface AppDelegate : NSObject
@end
@implementation AppDelegate
{
UIWindow *_window;
CC_VIEW<CCView> *_view;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if 0
[[TestbedSetup sharedSetup] setupApplication];
_window = [TestbedSetup sharedSetup].window;
_view = [TestbedSetup sharedSetup].view;
#else
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:PACKAGE_STORAGE_USERDEFAULTS_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
[CCSetup createCustomSetup];
[CCSetup sharedSetup].contentScale = [UIScreen mainScreen].scale;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
[CCSetup sharedSetup].contentScale *= 2;
[CCSetup sharedSetup].UIScale *= 0.5;
}
[CCSetup sharedSetup].assetScale = [CCSetup sharedSetup].contentScale;
CCFileLocator *locator = [CCFileLocator sharedFileLocator];
locator.untaggedContentScale = 4;
locator.searchPaths = @[
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"],
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Fonts"],
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Resources-shared"],
[[NSBundle mainBundle] resourcePath],
];
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
switch([CCSetup sharedSetup].graphicsAPI){
case CCGraphicsAPIGL:
{
_view = [[CCViewiOSGL alloc] initWithFrame:_window.bounds
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH24_STENCIL8_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
break;
}
#if __CC_METAL_SUPPORTED_AND_ENABLED
case CCGraphicsAPIMetal:
// TODO support MSAA, depth buffers, etc.
_view = [[CCMetalView alloc] initWithFrame:_window.bounds];
break;
#endif
default: NSAssert(NO, @"Internal error: Graphics API not set up.");
}
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view = _view;
viewController.wantsFullScreenLayout = YES;
_window.rootViewController = viewController;
// Need to force the window to be visible to set the initial view size on iOS < 8
[_window makeKeyAndVisible];
CCDirector *director = _view.director;
[CCDirector pushCurrentDirector:director];
[director presentScene:[MainMenu scene]];
[CCDirector popCurrentDirector];
[director startRunLoop];
#endif
return YES;
}
@end