Repository navigation
Expand file tree
/
Copy pathAppDelegate.cpp
More file actions
161 lines (137 loc) · 5.93 KB
/
Copy pathAppDelegate.cpp
File metadata and controls
161 lines (137 loc) · 5.93 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "AppDelegate.h"
#include "WorldScene.h"
// #define USE_AUDIO_ENGINE 1
// #define USE_SIMPLE_AUDIO_ENGINE 1
#define FULL_SCREEN_MODE 1
#if (!FULL_SCREEN_MODE)
#define FRAME_SIZE_NAME resolutionSizeNo4
#endif
#define RELATIVE_SIZE_MODE 1 // IS_DPI_ENABLED
#if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
#error "Don't use AudioEngine and SimpleAudioEngine at same time. Please just select one in your game!"
#endif
#if USE_AUDIO_ENGINE
#include "audio/include/AudioEngine.h"
using namespace cocos2d::experimental;
#elif USE_SIMPLE_AUDIO_ENGINE
#include "audio/include/SimpleAudioEngine.h"
using namespace CocosDenshion;
#endif
USING_NS_CC;
static cocos2d::Size designResolutionSize = cocos2d::Size(1920, 1080);
#if (!FULL_SCREEN_MODE || !RELATIVE_SIZE_MODE)
static cocos2d::Size resolutionSizeNo1 = cocos2d::Size(640, 360);
static cocos2d::Size resolutionSizeNo2 = cocos2d::Size(960, 540);
static cocos2d::Size resolutionSizeNo3 = cocos2d::Size(1440, 810);
static cocos2d::Size resolutionSizeNo4 = cocos2d::Size(1920, 1080);
static cocos2d::Size resolutionSizeNo5 = cocos2d::Size(2880, 1620);
static cocos2d::Size resolutionSizeNo6 = cocos2d::Size(3840, 2160);
static cocos2d::Size resolutionSizeNo7 = cocos2d::Size(4800, 2700);
static cocos2d::Size resolutionSizeNo8 = cocos2d::Size(5760, 3240);
static cocos2d::Size resolutionSizeNo9 = cocos2d::Size(7680, 4320);
#endif
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
#if USE_AUDIO_ENGINE
AudioEngine::end();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::end();
#endif
}
// if you want different context, modify value of glContextAttrs
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = { 8, 8, 8, 8, 24, 8 };
GLView::setGLContextAttrs(glContextAttrs);
}
// if you want to use package manager to install more packages,
// don't modify or remove this function
static int register_all_packages()
{
return 0; //flag for packages manager
}
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#if (FULL_SCREEN_MODE)
glview = GLViewImpl::createWithFullScreen("RTM");
#else
glview = GLViewImpl::createWithRect("RTM", cocos2d::Rect(0, 0, FRAME_SIZE_NAME.width, FRAME_SIZE_NAME.height));
#endif
#else
glview = GLViewImpl::create("RTM");
#endif
director->setOpenGLView(glview);
}
// turn on display FPS
//director->setDisplayStats(true);
// set FPS. default value is 1.0/60 if you don't call this
//director->setAnimationInterval(1.f / 60);
// Set design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
#if (!RELATIVE_SIZE_MODE)
// Set correct scale
auto frameSize = glview->getFrameSize();
if (frameSize.height > resolutionSizeNo8.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo9.height / designResolutionSize.height, resolutionSizeNo9.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo7.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo8.height / designResolutionSize.height, resolutionSizeNo8.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo6.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo7.height / designResolutionSize.height, resolutionSizeNo7.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo5.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo6.height / designResolutionSize.height, resolutionSizeNo6.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo4.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo5.height / designResolutionSize.height, resolutionSizeNo5.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo3.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo4.height / designResolutionSize.height, resolutionSizeNo4.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo2.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo3.height / designResolutionSize.height, resolutionSizeNo3.width / designResolutionSize.width));
}
else if (frameSize.height > resolutionSizeNo1.height) {
director->setContentScaleFactor(MIN(resolutionSizeNo2.height / designResolutionSize.height, resolutionSizeNo2.width / designResolutionSize.width));
}
else {
director->setContentScaleFactor(MIN(resolutionSizeNo1.height / designResolutionSize.height, resolutionSizeNo1.width / designResolutionSize.width));
}
#endif
register_all_packages();
// create scene. it's autorelease object
auto scene = rtm::WorldScene::Create();
// run
director->runWithScene(scene);
return true;
}
// This function will be called when app is inactive. Note, when receiving phone call it is invoked.
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();
#if USE_AUDIO_ENGINE
AudioEngine::pauseAll();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
SimpleAudioEngine::getInstance()->pauseAllEffects();
#endif
}
// this function will be called when app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();
#if USE_AUDIO_ENGINE
AudioEngine::resumeAll();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
SimpleAudioEngine::getInstance()->resumeAllEffects();
#endif
}