AppDelegate.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated May 1, 2019. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2019, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
  19. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
  24. * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #include "AppDelegate.h"
  30. #include <vector>
  31. #include <string>
  32. #include "RaptorExample.h"
  33. #include "BatchingExample.h"
  34. #include "CoinExample.h"
  35. #include "SkeletonRendererSeparatorExample.h"
  36. #include <spine/Debug.h>
  37. #include "AppMacros.h"
  38. #include <spine/SkeletonTwoColorBatch.h>
  39. USING_NS_CC;
  40. using namespace std;
  41. DebugExtension debugExtension(SpineExtension::getInstance());
  42. AppDelegate::AppDelegate () {
  43. }
  44. AppDelegate::~AppDelegate () {
  45. SkeletonBatch::destroyInstance();
  46. SkeletonTwoColorBatch::destroyInstance();
  47. debugExtension.reportLeaks();
  48. }
  49. bool AppDelegate::applicationDidFinishLaunching () {
  50. // initialize director
  51. auto director = Director::getInstance();
  52. auto glview = director->getOpenGLView();
  53. if (!glview) {
  54. GLContextAttrs attrs = { 8, 8, 8, 8, 0, 0 };
  55. GLView::setGLContextAttrs(attrs);
  56. glview = GLViewImpl::create("Spine Example");
  57. director->setOpenGLView(glview);
  58. }
  59. // Set the design resolution
  60. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
  61. // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
  62. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
  63. #else
  64. glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
  65. #endif
  66. cocos2d::Size frameSize = glview->getFrameSize();
  67. vector<string> searchPath;
  68. // In this demo, we select resource according to the frame's height.
  69. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
  70. // We use the ratio of resource's height to the height of design resolution,
  71. // this can make sure that the resource's height could fit for the height of design resolution.
  72. if (frameSize.height > mediumResource.size.height) {
  73. // if the frame's height is larger than the height of medium resource size, select large resource.
  74. searchPath.push_back(largeResource.directory);
  75. director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
  76. } else if (frameSize.height > smallResource.size.height) {
  77. // if the frame's height is larger than the height of small resource size, select medium resource.
  78. searchPath.push_back(mediumResource.directory);
  79. director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
  80. } else {
  81. // if the frame's height is smaller than the height of medium resource size, select small resource.
  82. searchPath.push_back(smallResource.directory);
  83. director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
  84. }
  85. searchPath.push_back("common");
  86. // set search path
  87. FileUtils::getInstance()->setSearchPaths(searchPath);
  88. // turn on display FPS
  89. director->setDisplayStats(true);
  90. // set FPS. the default value is 1.0/60 if you don't call this
  91. director->setAnimationInterval(1.0f / 60);
  92. // Set the Debug wrapper extension so we know about memory leaks.
  93. SpineExtension::setInstance(&debugExtension);
  94. // create a scene. it's an autorelease object
  95. //auto scene = RaptorExample::scene();
  96. auto scene = CoinExample::scene();
  97. // run
  98. director->runWithScene(scene);
  99. return true;
  100. }
  101. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  102. void AppDelegate::applicationDidEnterBackground () {
  103. Director::getInstance()->stopAnimation();
  104. // if you use SimpleAudioEngine, it must be paused
  105. // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  106. }
  107. // this function will be called when the app is active again
  108. void AppDelegate::applicationWillEnterForeground () {
  109. Director::getInstance()->startAnimation();
  110. // if you use SimpleAudioEngine, it must resume here
  111. // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  112. }