Blame view

ios/Runner/Wowgame/Classes/CocosAppDelegate.cpp 4.05 KB
cb213901   xiaoyu   添加一个游戏的源码和编译选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /****************************************************************************
   Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
   
   http://www.cocos2d-x.org
   
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
   
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
25
26
  #include "CocosAppDelegate.h"
  #include "HelloWorldScene.h"
68a4c50a   xiaoyu   Merge remote-trac...
27
28
29
30
31
32
33
34
35
  
  
  #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  #include "NativeAndroid/AndroidUtils_cpp.h"
  #endif
  
  
  
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
36
  // #define USE_AUDIO_ENGINE 1
cb213901   xiaoyu   添加一个游戏的源码和编译选项
37
38
39
  
  #if USE_AUDIO_ENGINE
  #include "audio/include/AudioEngine.h"
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
40
  using namespace cocos2d::experimental;
cb213901   xiaoyu   添加一个游戏的源码和编译选项
41
42
43
44
45
46
47
  #endif
  
  USING_NS_CC;
  
  static cocos2d::Size designResolutionSize = cocos2d::Size(2732, 2048);
  static cocos2d::Size tinyResolutionSize = cocos2d::Size(1366, 1024);
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
48
  CocosAppDelegate::CocosAppDelegate()
cb213901   xiaoyu   添加一个游戏的源码和编译选项
49
50
51
  {
  }
  
68a4c50a   xiaoyu   Merge remote-trac...
52
  CocosAppDelegate::~CocosAppDelegate()
cb213901   xiaoyu   添加一个游戏的源码和编译选项
53
  {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
54
  #if USE_AUDIO_ENGINE
cb213901   xiaoyu   添加一个游戏的源码和编译选项
55
      AudioEngine::end();
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
56
  #endif
68a4c50a   xiaoyu   Merge remote-trac...
57
58
59
60
61
      
      SpriteFrameCache::getInstance()->removeSpriteFrames();
      Director::getInstance()->getTextureCache()->removeAllTextures();
  
  
cb213901   xiaoyu   添加一个游戏的源码和编译选项
62
63
64
65
  }
  
  // if you want a different context, modify the value of glContextAttrs
  // it will affect all platforms
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
66
  void CocosAppDelegate::initGLContextAttrs()
cb213901   xiaoyu   添加一个游戏的源码和编译选项
67
68
69
70
71
72
73
  {
      // set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
      GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
  
      GLView::setGLContextAttrs(glContextAttrs);
  }
  
68a4c50a   xiaoyu   Merge remote-trac...
74
  // if you want to use the package manager to install more packages,
cb213901   xiaoyu   添加一个游戏的源码和编译选项
75
76
77
78
79
80
  // don't modify or remove this function
  static int register_all_packages()
  {
      return 0; //flag for packages manager
  }
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
81
  bool CocosAppDelegate::applicationDidFinishLaunching() {
cb213901   xiaoyu   添加一个游戏的源码和编译选项
82
83
84
85
      // initialize director
      auto director = Director::getInstance();
      auto glview = director->getOpenGLView();
      if(!glview) {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
86
87
88
89
90
  #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
          glview = GLViewImpl::createWithRect("bjgame", cocos2d::Rect(0, 0, tinyResolutionSize.width, tinyResolutionSize.height));
  #else
          glview = GLViewImpl::create("bjgame");
  #endif
cb213901   xiaoyu   添加一个游戏的源码和编译选项
91
92
          director->setOpenGLView(glview);
      }
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
93
94
      // Set the design resolution
      glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::FIXED_HEIGHT);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
95
96
  
      // turn on display FPS
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
97
98
99
      director->setDisplayStats(false);
      // set FPS. the default value is 1.0/60 if you don't call this
      director->setAnimationInterval(1.0f / 60);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
100
  
cb213901   xiaoyu   添加一个游戏的源码和编译选项
101
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
102
103
104
      register_all_packages();
      // create a scene. it's an autorelease object
      auto scene = HelloWorld::createScene();
cb213901   xiaoyu   添加一个游戏的源码和编译选项
105
      // run
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
106
      director->runWithScene(scene);
cb213901   xiaoyu   添加一个游戏的源码和编译选项
107
108
109
110
111
  
      return true;
  }
  
  // This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
112
  void CocosAppDelegate::applicationDidEnterBackground() {
cb213901   xiaoyu   添加一个游戏的源码和编译选项
113
      Director::getInstance()->stopAnimation();
cb213901   xiaoyu   添加一个游戏的源码和编译选项
114
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
115
116
  #if USE_AUDIO_ENGINE
      AudioEngine::pauseAll();
cb213901   xiaoyu   添加一个游戏的源码和编译选项
117
  #endif
cb213901   xiaoyu   添加一个游戏的源码和编译选项
118
119
120
  }
  
  // this function will be called when the app is active again
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
121
  void CocosAppDelegate::applicationWillEnterForeground() {
cb213901   xiaoyu   添加一个游戏的源码和编译选项
122
      Director::getInstance()->startAnimation();
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
123
124
125
126
  
  #if USE_AUDIO_ENGINE
      AudioEngine::resumeAll();
  #endif
cb213901   xiaoyu   添加一个游戏的源码和编译选项
127
  }