AppDelegate.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "AppDelegate.h"
  2. #include <vector>
  3. #include <string>
  4. #include "ExampleScene.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. CCDirector* director = CCDirector::sharedDirector();
  14. CCEGLView* view = CCEGLView::sharedOpenGLView();
  15. director->setOpenGLView(view);
  16. view->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
  17. // In this demo, we select resource according to the frame's height.
  18. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
  19. // We use the ratio of resource's height to the height of design resolution,
  20. // this can make sure that the resource's height could fit for the height of design resolution.
  21. vector<string> searchPath;
  22. CCSize frameSize = view->getFrameSize();
  23. if (frameSize.height > mediumResource.size.height) {
  24. // if the frame's height is larger than the height of medium resource size, select large resource.
  25. searchPath.push_back(largeResource.directory);
  26. director->setContentScaleFactor( //
  27. MIN(largeResource.size.height / designResolutionSize.height, //
  28. largeResource.size.width / designResolutionSize.width));
  29. } else if (frameSize.height > smallResource.size.height) {
  30. // if the frame's height is larger than the height of small resource size, select medium resource.
  31. searchPath.push_back(mediumResource.directory);
  32. director->setContentScaleFactor( //
  33. MIN(mediumResource.size.height / designResolutionSize.height, //
  34. mediumResource.size.width / designResolutionSize.width));
  35. } else {
  36. // if the frame's height is smaller than the height of medium resource size, select small resource.
  37. searchPath.push_back(smallResource.directory);
  38. director->setContentScaleFactor( //
  39. MIN(smallResource.size.height / designResolutionSize.height, //
  40. smallResource.size.width / designResolutionSize.width));
  41. }
  42. searchPath.push_back("common");
  43. CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);
  44. director->setDisplayStats(true);
  45. director->setAnimationInterval(1.0 / 60);
  46. CCScene *pScene = ExampleScene::scene();
  47. director->runWithScene(pScene);
  48. return true;
  49. }
  50. void AppDelegate::applicationDidEnterBackground () {
  51. CCDirector::sharedDirector()->stopAnimation();
  52. // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  53. }
  54. void AppDelegate::applicationWillEnterForeground () {
  55. CCDirector::sharedDirector()->startAnimation();
  56. // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  57. }