AppDelegate.cpp 5.7 KB

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