AppDelegate.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #include "AppDelegate.h"
  31. #include <vector>
  32. #include <string>
  33. #include "RaptorExample.h"
  34. #include "BatchingExample.h"
  35. #include "CoinExample.h"
  36. #include "SkeletonRendererSeparatorExample.h"
  37. #include "AppMacros.h"
  38. USING_NS_CC;
  39. using namespace std;
  40. AppDelegate::AppDelegate () {
  41. }
  42. AppDelegate::~AppDelegate () {
  43. }
  44. bool AppDelegate::applicationDidFinishLaunching () {
  45. // initialize director
  46. auto director = Director::getInstance();
  47. auto glview = director->getOpenGLView();
  48. if (!glview) {
  49. glview = GLViewImpl::create("Spine Example");
  50. director->setOpenGLView(glview);
  51. }
  52. // Set the design resolution
  53. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
  54. // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
  55. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
  56. #else
  57. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
  58. #endif
  59. cocos2d::Size frameSize = glview->getFrameSize();
  60. vector<string> searchPath;
  61. // In this demo, we select resource according to the frame's height.
  62. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
  63. // We use the ratio of resource's height to the height of design resolution,
  64. // this can make sure that the resource's height could fit for the height of design resolution.
  65. if (frameSize.height > mediumResource.size.height) {
  66. // if the frame's height is larger than the height of medium resource size, select large resource.
  67. searchPath.push_back(largeResource.directory);
  68. director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
  69. } else if (frameSize.height > smallResource.size.height) {
  70. // if the frame's height is larger than the height of small resource size, select medium resource.
  71. searchPath.push_back(mediumResource.directory);
  72. director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
  73. } else {
  74. // if the frame's height is smaller than the height of medium resource size, select small resource.
  75. searchPath.push_back(smallResource.directory);
  76. director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
  77. }
  78. searchPath.push_back("common");
  79. // set search path
  80. FileUtils::getInstance()->setSearchPaths(searchPath);
  81. // turn on display FPS
  82. director->setDisplayStats(true);
  83. // set FPS. the default value is 1.0/60 if you don't call this
  84. director->setAnimationInterval(1.0f / 60);
  85. // create a scene. it's an autorelease object
  86. //auto scene = RaptorExample::scene();
  87. auto scene = SkeletonRendererSeparatorExample::scene();
  88. // run
  89. director->runWithScene(scene);
  90. return true;
  91. }
  92. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  93. void AppDelegate::applicationDidEnterBackground () {
  94. Director::getInstance()->stopAnimation();
  95. // if you use SimpleAudioEngine, it must be paused
  96. // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  97. }
  98. // this function will be called when the app is active again
  99. void AppDelegate::applicationWillEnterForeground () {
  100. Director::getInstance()->startAnimation();
  101. // if you use SimpleAudioEngine, it must resume here
  102. // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  103. }