AppDelegate.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <spine/Debug.h>
  38. #include "AppMacros.h"
  39. USING_NS_CC;
  40. using namespace std;
  41. DebugExtension debugExtension(SpineExtension::getInstance());
  42. AppDelegate::AppDelegate () {
  43. }
  44. AppDelegate::~AppDelegate () {
  45. debugExtension.reportLeaks();
  46. }
  47. bool AppDelegate::applicationDidFinishLaunching () {
  48. // initialize director
  49. auto director = Director::getInstance();
  50. auto glview = director->getOpenGLView();
  51. if (!glview) {
  52. glview = GLViewImpl::create("Spine Example");
  53. director->setOpenGLView(glview);
  54. }
  55. // Set the design resolution
  56. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
  57. // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
  58. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
  59. #else
  60. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
  61. #endif
  62. Size frameSize = glview->getFrameSize();
  63. vector<string> searchPath;
  64. // In this demo, we select resource according to the frame's height.
  65. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
  66. // We use the ratio of resource's height to the height of design resolution,
  67. // this can make sure that the resource's height could fit for the height of design resolution.
  68. if (frameSize.height > mediumResource.size.height) {
  69. // if the frame's height is larger than the height of medium resource size, select large resource.
  70. searchPath.push_back(largeResource.directory);
  71. director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
  72. } else if (frameSize.height > smallResource.size.height) {
  73. // if the frame's height is larger than the height of small resource size, select medium resource.
  74. searchPath.push_back(mediumResource.directory);
  75. director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
  76. } else {
  77. // if the frame's height is smaller than the height of medium resource size, select small resource.
  78. searchPath.push_back(smallResource.directory);
  79. director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
  80. }
  81. searchPath.push_back("common");
  82. // set search path
  83. FileUtils::getInstance()->setSearchPaths(searchPath);
  84. // turn on display FPS
  85. director->setDisplayStats(true);
  86. // set FPS. the default value is 1.0/60 if you don't call this
  87. director->setAnimationInterval(1.0f / 60);
  88. // Set the Debug wrapper extension so we know about memory leaks.
  89. SpineExtension::setInstance(&debugExtension);
  90. // create a scene. it's an autorelease object
  91. //auto scene = RaptorExample::scene();
  92. auto scene = CoinExample::scene();
  93. // run
  94. director->runWithScene(scene);
  95. return true;
  96. }
  97. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  98. void AppDelegate::applicationDidEnterBackground () {
  99. Director::getInstance()->stopAnimation();
  100. // if you use SimpleAudioEngine, it must be paused
  101. // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  102. }
  103. // this function will be called when the app is active again
  104. void AppDelegate::applicationWillEnterForeground () {
  105. Director::getInstance()->startAnimation();
  106. // if you use SimpleAudioEngine, it must resume here
  107. // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  108. }