PuzzleSDK
testsAppDelegate.mm
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2013 cocos2d-x.org
3 Copyright (c) 2013-2016 Chukong Technologies Inc.
4 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5
6 http://www.cocos2d-x.org
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 ****************************************************************************/
26
27#import "testsAppDelegate.h"
28
29#import "platform/ios/CCEAGLView-ios.h"
30#import "cocos2d.h"
31#import "../../Classes/AppDelegate.h"
33
34@implementation AppController
35
36#pragma mark -
37#pragma mark Application lifecycle
38
39// cocos2d application instance
41
42- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
43{
44
45 cocos2d::Application *app = cocos2d::Application::getInstance();
46 app->initGLContextAttrs();
47 cocos2d::GLViewImpl::convertAttrs();
48
49 // Override point for customization after application launch.
50
51 // Add the view controller's view to the window and display.
52 window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
53
54 // Init the CCEAGLView
55 CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
56 pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
57 depthFormat: cocos2d::GLViewImpl::_depthFormat
58 preserveBackbuffer: NO
59 sharegroup: nil
60 multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
61 numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
62
63#if !defined(CC_TARGET_OS_TVOS)
64 [eaglView setMultipleTouchEnabled:YES];
65#endif
66
67 // Use RootViewController manage CCEAGLView
68 viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
69#if !defined(CC_TARGET_OS_TVOS)
70 viewController.extendedLayoutIncludesOpaqueBars = YES;
71#endif
72 viewController.view = eaglView;
73
74 // Set RootViewController to window
75 if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
76 {
77 // warning: addSubView doesn't work on iOS6
78 [window addSubview: viewController.view];
79 }
80 else
81 {
82 // use this method on ios6
83 [window setRootViewController:viewController];
84 }
85
86 [window makeKeyAndVisible];
87
88#if !defined(CC_TARGET_OS_TVOS)
89 [viewController prefersStatusBarHidden];
90#endif
91
92 // IMPORTANT: Setting the GLView should be done after creating the RootViewController
93 cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView);
94 cocos2d::Director::getInstance()->setOpenGLView(glview);
95
96 app->run();
97
98 return YES;
99}
100
101
102- (void)applicationWillResignActive:(UIApplication *)application {
103 /*
104 Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
105 Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
106 */
107 //We don't need to call this method any more. It will interrupt user defined game pause&resume logic
108// cocos2d::Director::getInstance()->pause();
109}
110
111- (void)applicationDidBecomeActive:(UIApplication *)application {
112 /*
113 Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
114 */
115 //We don't need to call this method any more. It will interrupt user defined game pause&resume logic
116// cocos2d::Director::getInstance()->resume();
117}
118
119- (void)applicationDidEnterBackground:(UIApplication *)application {
120 /*
121 Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
122 If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
123 */
124 cocos2d::Application::getInstance()->applicationDidEnterBackground();
125}
126
127- (void)applicationWillEnterForeground:(UIApplication *)application {
128 /*
129 Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
130 */
131 cocos2d::Application::getInstance()->applicationWillEnterForeground();
132}
133
134- (void)applicationWillTerminate:(UIApplication *)application {
135 /*
136 Called when the application is about to terminate.
137 See also applicationDidEnterBackground:.
138 */
139}
140
141
142#pragma mark -
143#pragma mark Memory management
144
145- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
146 /*
147 Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
148 */
149}
150
151
152- (void)dealloc {
153 [window release];
154 [super dealloc];
155}
156
157
158@end
The cocos2d Application.
Definition: AppDelegate.h:39
RootViewController * viewController
UIWindow * window
static AppDelegate s_sharedApplication