PuzzleSDK
AppDelegate.cpp
浏览该文件的文档.
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#include "AppDelegate.h"
27
28#include "cocos2d.h"
29#include "controller.h"
30// #include "editor-support/cocostudio/CocoStudio.h"
31#include "extensions/cocos-ext.h"
32
34
36: _testController(nullptr)
37{
38}
39
41{
42 //SimpleAudioEngine::end();
43 //TODO: minggo
44 // cocostudio::ArmatureDataManager::destroyInstance();
45}
46
47// if you want a different context, modify the value of glContextAttrs
48// it will affect all platforms
50{
51 // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
52 GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
53
54 GLView::setGLContextAttrs(glContextAttrs);
55}
56
58{
59 // As an example, load config file
60 // FIXME:: This should be loaded before the Director is initialized,
61 // FIXME:: but at this point, the director is already initialized
62 Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
63
64 // initialize director
65 auto director = Director::getInstance();
66 auto glview = director->getOpenGLView();
67 if(!glview) {
68 glview = GLViewImpl::create("Cpp Tests");
69 director->setOpenGLView(glview);
70 }
71
72 director->setDisplayStats(true);
73 director->setAnimationInterval(1.0f / 60);
74
75 auto screenSize = glview->getFrameSize();
76 auto designSize = Size(480, 320);
77
78 auto fileUtils = FileUtils::getInstance();
79 std::vector<std::string> searchPaths;
80
81 if (screenSize.height > 320)
82 {
83 auto resourceSize = Size(960, 640);
84 searchPaths.push_back("hd");
85 searchPaths.push_back("ccs-res/hd");
86 searchPaths.push_back("ccs-res");
87 searchPaths.push_back("Manifests");
88 director->setContentScaleFactor(resourceSize.height/designSize.height);
89
90 searchPaths.push_back("hd/ActionTimeline");
91 }
92 else
93 {
94 searchPaths.push_back("ccs-res");
95
96 searchPaths.push_back("ActionTimeline");
97 }
98
99 fileUtils->setSearchPaths(searchPaths);
100
101 glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
102
103 // Enable Remote Console
104 auto console = director->getConsole();
105 console->listenOnTCP(5678);
106
108
109 return true;
110}
111
112// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
114{
115 if (_testController)
116 {
117// _testController->onEnterBackground();
118 }
119
120 Director::getInstance()->stopAnimation();
121}
122
123// this function will be called when the app is active again
125{
126 if (_testController)
127 {
128// _testController->onEnterForeground();
129 }
130
131 Director::getInstance()->startAnimation();
132}
USING_NS_CC
Definition: AppDelegate.cpp:33
virtual void applicationDidEnterBackground()
Called when the application moves to the background
virtual void initGLContextAttrs()
Definition: AppDelegate.cpp:49
TestController * _testController
Definition: AppDelegate.h:66
virtual bool applicationDidFinishLaunching()
Implement Director and cocos2d::Scene* init code here.
Definition: AppDelegate.cpp:57
virtual ~AppDelegate()
Definition: AppDelegate.cpp:40
virtual void applicationWillEnterForeground()
Called when the application reenters the foreground
static TestController * getInstance()
Definition: controller.cpp:458