AppDelegate.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "AppDelegate.h"
  2. #include <vector>
  3. #include <string>
  4. #include "SpineboyExample.h"
  5. #include "AppMacros.h"
  6. USING_NS_CC;
  7. using namespace std;
  8. AppDelegate::AppDelegate () {
  9. }
  10. AppDelegate::~AppDelegate () {
  11. }
  12. bool AppDelegate::applicationDidFinishLaunching () {
  13. // initialize director
  14. CCDirector* director = CCDirector::sharedDirector();
  15. CCEGLView* view = CCEGLView::sharedOpenGLView();
  16. director->setOpenGLView(view);
  17. view->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
  18. CCSize frameSize = view->getFrameSize();
  19. vector<string> searchPath;
  20. // In this demo, we select resource according to the frame's height.
  21. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
  22. // We use the ratio of resource's height to the height of design resolution,
  23. // this can make sure that the resource's height could fit for the height of design resolution.
  24. if (frameSize.height > mediumResource.size.height) {
  25. // if the frame's height is larger than the height of medium resource size, select large resource.
  26. searchPath.push_back(largeResource.directory);
  27. director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
  28. } else if (frameSize.height > smallResource.size.height) {
  29. // if the frame's height is larger than the height of small resource size, select medium resource.
  30. searchPath.push_back(mediumResource.directory);
  31. director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
  32. } else {
  33. // if the frame's height is smaller than the height of medium resource size, select small resource.
  34. searchPath.push_back(smallResource.directory);
  35. director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
  36. }
  37. searchPath.push_back("common");
  38. // set searching path
  39. CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);
  40. // turn on display FPS
  41. director->setDisplayStats(true);
  42. // set FPS. the default value is 1.0/60 if you don't call this
  43. director->setAnimationInterval(1.0 / 60);
  44. // create a scene. it's an autorelease object
  45. auto scene = SpineboyExample::scene();
  46. // run
  47. director->runWithScene(scene);
  48. return true;
  49. }
  50. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  51. void AppDelegate::applicationDidEnterBackground () {
  52. CCDirector::sharedDirector()->stopAnimation();
  53. // if you use SimpleAudioEngine, it must be paused
  54. // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  55. }
  56. // this function will be called when the app is active again
  57. void AppDelegate::applicationWillEnterForeground () {
  58. CCDirector::sharedDirector()->startAnimation();
  59. // if you use SimpleAudioEngine, it must resume here
  60. // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  61. }