-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBVAppDelegate.mm
129 lines (99 loc) · 4.15 KB
/
BVAppDelegate.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
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
120
121
122
123
124
125
126
127
128
129
//
// BVAppDelegate.m
// BreakVaders
//
// Created by Jonathan Beilin on 12/5/13.
// Copyright (c) 2013 Jonathan Beilin. All rights reserved.
//
#import "BVAppDelegate.h"
#import "OverlayViewController.h"
#import "cocos2d.h"
#import "PongVaderScene.h"
#import "BVLocalOptions.h"
#import "BVGameKitHelper.h"
#import "GAI.h"
#import <Crashlytics/Crashlytics.h>
@implementation BVAppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Crashlytics startWithAPIKey:CRASHID];
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// cocos2d will inherit these values
[_window setUserInteractionEnabled:YES];
[_window setMultipleTouchEnabled:YES];
CCGLView *glView = [CCGLView viewWithFrame:[_window bounds]
pixelFormat:kEAGLColorFormatRGBA8];
[glView setMultipleTouchEnabled:YES];
CCDirectorIOS *dir = (CCDirectorIOS *) [CCDirector sharedDirector];
if ( ![dir enableRetinaDisplay:NO] )
CCLOG(@"Retina Display Not supported");
_window.rootViewController = dir;
dir.wantsFullScreenLayout = YES;
[dir setDisplayStats:NO];
[dir setAnimationInterval:1.0/60];
[dir setView:glView];
[dir setProjection:kCCDirectorProjection2D];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
// On iPad HD : "-ipadhd", "-ipad", "-hd"
// On iPad : "-ipad", "-hd"
// On iPhone HD: "-hd"
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"
// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
[dir runWithScene: (CCScene *) [PongVader scene]];
// jump into the initial state
[GameState handleEvent: [[StateMainMenu alloc] init]];
_window.backgroundColor = [UIColor blackColor];
[_window makeKeyAndVisible];
[GAI sharedInstance].trackUncaughtExceptions = YES;
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:GAID];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gamecenter"]) {
[[BVGameKitHelper sharedGameKitHelper] authenticatePlayer];
}
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[[PongVader getInstance] terminating];
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[PongVader getInstance] terminating];
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CCDirector sharedDirector] stopAnimation]; // call this to make sure you don't start a second display link!
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];
GameState *cur = [GameState getCurrentState];
if ([cur isKindOfClass:[StateGetReady class]] ||
[cur isKindOfClass:[StatePlaying class]] ||
[cur isKindOfClass:[StatePostPlaying class]] ||
[cur isKindOfClass:[StateMainMenu class]] ||
[cur isKindOfClass:[StateMovie class]]) {
[GameState handleEvent: [[StateMainMenu alloc] init]];
}
}
- (void)applicationWillTerminate:(UIApplication *)application {
[[PongVader getInstance] terminating];
[[CCDirector sharedDirector] end];
CC_DIRECTOR_END();
}
- (void)applicationSignificantTimeChange:(UIApplication *)application {
[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}
@end