回答編集履歴
1
ソースが長いので必要な部分だけ残すようにしました。また、ContentScaleFactorが書き換わっている部分の説明を追記しました。
test
CHANGED
@@ -38,39 +38,7 @@
|
|
38
38
|
|
39
39
|
#include "AppDelegate.h"
|
40
40
|
|
41
|
-
#include "HelloWorldScene.h"
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#define USE_AUDIO_ENGINE 1
|
46
|
-
|
47
|
-
// #define USE_SIMPLE_AUDIO_ENGINE 1
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
|
52
|
-
|
53
|
-
#error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
|
54
|
-
|
55
|
-
|
41
|
+
...
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#if USE_AUDIO_ENGINE
|
60
|
-
|
61
|
-
#include "audio/include/AudioEngine.h"
|
62
|
-
|
63
|
-
using namespace cocos2d::experimental;
|
64
|
-
|
65
|
-
#elif USE_SIMPLE_AUDIO_ENGINE
|
66
|
-
|
67
|
-
#include "audio/include/SimpleAudioEngine.h"
|
68
|
-
|
69
|
-
using namespace CocosDenshion;
|
70
|
-
|
71
|
-
#endif
|
72
|
-
|
73
|
-
|
74
42
|
|
75
43
|
USING_NS_CC;
|
76
44
|
|
@@ -84,67 +52,7 @@
|
|
84
52
|
|
85
53
|
static const float CONTENT_SCALE_FACTOR = 1.0;
|
86
54
|
|
87
|
-
|
88
|
-
|
89
|
-
AppDelegate::AppDelegate()
|
90
|
-
|
91
|
-
{
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
AppDelegate::~AppDelegate()
|
98
|
-
|
99
|
-
{
|
100
|
-
|
101
|
-
#if USE_AUDIO_ENGINE
|
102
|
-
|
103
|
-
AudioEngine::end();
|
104
|
-
|
105
|
-
#elif USE_SIMPLE_AUDIO_ENGINE
|
106
|
-
|
107
|
-
SimpleAudioEngine::end();
|
108
|
-
|
109
|
-
|
55
|
+
...
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
// if you want a different context, modify the value of glContextAttrs
|
116
|
-
|
117
|
-
// it will affect all platforms
|
118
|
-
|
119
|
-
void AppDelegate::initGLContextAttrs()
|
120
|
-
|
121
|
-
{
|
122
|
-
|
123
|
-
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
|
124
|
-
|
125
|
-
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
GLView::setGLContextAttrs(glContextAttrs);
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
// if you want to use the package manager to install more packages,
|
136
|
-
|
137
|
-
// don't modify or remove this function
|
138
|
-
|
139
|
-
static int register_all_packages()
|
140
|
-
|
141
|
-
{
|
142
|
-
|
143
|
-
return 0; //flag for packages manager
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
56
|
|
149
57
|
bool AppDelegate::applicationDidFinishLaunching() {
|
150
58
|
|
@@ -210,51 +118,77 @@
|
|
210
118
|
|
211
119
|
}
|
212
120
|
|
213
|
-
|
214
|
-
|
215
|
-
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
|
216
|
-
|
217
|
-
void AppDelegate::applicationDidEnterBackground() {
|
218
|
-
|
219
|
-
|
121
|
+
```
|
220
122
|
|
221
123
|
|
222
124
|
|
223
|
-
#if USE_AUDIO_ENGINE
|
224
|
-
|
225
|
-
AudioEngine::pauseAll();
|
226
|
-
|
227
|
-
#elif USE_SIMPLE_AUDIO_ENGINE
|
228
|
-
|
229
|
-
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
230
|
-
|
231
|
-
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
232
|
-
|
233
|
-
#
|
125
|
+
### 追記
|
234
|
-
|
235
|
-
}
|
236
126
|
|
237
127
|
|
238
128
|
|
239
|
-
|
129
|
+
なお、以下が初期状態のAppDelegate.cppでContentScaleFactorをデバイスの画面サイズによって変更している箇所です。
|
240
130
|
|
241
|
-
|
131
|
+
これを残しておくと、今回のように意図しない動きになってしまうので、
|
242
132
|
|
243
|
-
|
133
|
+
cocos newでプロジェクトを作った後は、毎回削除しましょう。
|
244
134
|
|
245
135
|
|
246
136
|
|
247
|
-
|
137
|
+
```cpp
|
248
138
|
|
249
|
-
|
139
|
+
...
|
250
140
|
|
251
|
-
|
141
|
+
static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
|
252
142
|
|
253
|
-
|
143
|
+
static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 320);
|
254
144
|
|
255
|
-
|
145
|
+
static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768);
|
256
146
|
|
147
|
+
static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536);
|
148
|
+
|
149
|
+
...
|
150
|
+
|
151
|
+
bool AppDelegate::applicationDidFinishLaunching() {
|
152
|
+
|
153
|
+
...
|
154
|
+
|
155
|
+
// Set the design resolution
|
156
|
+
|
157
|
+
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
|
158
|
+
|
159
|
+
auto frameSize = glview->getFrameSize();
|
160
|
+
|
161
|
+
// if the frame's height is larger than the height of medium size.
|
162
|
+
|
163
|
+
if (frameSize.height > mediumResolutionSize.height)
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
// if the frame's height is larger than the height of small size.
|
172
|
+
|
173
|
+
else if (frameSize.height > smallResolutionSize.height)
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
// if the frame's height is smaller than the height of medium size.
|
182
|
+
|
257
|
-
|
183
|
+
else
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
...
|
258
192
|
|
259
193
|
}
|
260
194
|
|