AppDelegate.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "AppDelegate.h"
  2. #include "TestScene.h"
  3. USING_NS_CC;
  4. #include "common/BigFile.h"
  5. //#include "ProjectLauncher.h"
  6. static cocos2d::Size designResolutionSize = cocos2d::Size(640, 1136);
  7. static cocos2d::Size smallResolutionSize = cocos2d::Size(640, 1136);
  8. static cocos2d::Size mediumResolutionSize = cocos2d::Size(640, 1136);
  9. static cocos2d::Size largeResolutionSize = cocos2d::Size(640, 1136);
  10. AppDelegate::AppDelegate()
  11. {
  12. }
  13. AppDelegate::~AppDelegate()
  14. {
  15. }
  16. // if you want a different context, modify the value of glContextAttrs
  17. // it will affect all platforms
  18. void AppDelegate::initGLContextAttrs()
  19. {
  20. // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
  21. GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  22. GLView::setGLContextAttrs(glContextAttrs);
  23. }
  24. // if you want to use the package manager to install more packages,
  25. // don't modify or remove this function
  26. static int register_all_packages()
  27. {
  28. return 0; //flag for packages manager
  29. }
  30. bool AppDelegate::applicationDidFinishLaunching() {
  31. // initialize director
  32. BigFile::getInstance();
  33. FileUtils* fileUtils = FileUtils::getInstance();
  34. // string writePath = fileUtils->getWritablePath();
  35. //#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
  36. // writePath = writePath + BulldogPlatform::getInstance()->getPackageName()+"/";
  37. // if(!fileUtils->isDirectoryExist(writePath)){
  38. // fileUtils->createDirectory(writePath);
  39. // }
  40. // fileUtils->setWritablePath(writePath);
  41. //#else
  42. //
  43. //#endif
  44. Director* director = Director::getInstance();
  45. director->getScheduler()->setTimeScale(1.f);
  46. auto glview = director->getOpenGLView();
  47. if(!glview) {
  48. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
  49. Rect _rect;
  50. float _scale;
  51. _rect = Rect(0, 0, 720, 1280);
  52. _scale=0.8f;
  53. glview = GLViewImpl::createWithRect("ccProj", cocos2d::Rect(0, 0, designResolutionSize.width/2, designResolutionSize.height/2));
  54. #else
  55. glview = GLViewImpl::create("ccProj");
  56. #endif
  57. director->setOpenGLView(glview);
  58. }
  59. fileUtils->addSearchPath("res");
  60. fileUtils->addSearchPath("../Resources");
  61. // turn on display FPS
  62. director->setDisplayStats(true);
  63. // set FPS. the default value is 1.0/60 if you don't call this
  64. director->setAnimationInterval(1.0f/60);
  65. Size designSz(640,1136);//640X1136
  66. Size winSz = director->getWinSize();
  67. float factor1 = designSz.width*1.0/designSz.height;//0.667
  68. float factor2 = winSz.width/winSz.height;//0.561
  69. Size setSize(designSz.width,designSz.height);
  70. if(factor2<factor1)
  71. {
  72. glview->setDesignResolutionSize(designSz.width,designSz.width/factor2,ResolutionPolicy::FIXED_WIDTH);
  73. }
  74. else
  75. {
  76. glview->setDesignResolutionSize(factor2*designSz.height,designSz.height,ResolutionPolicy::FIXED_HEIGHT);
  77. }
  78. register_all_packages();
  79. auto scene = TestScene::createScene();
  80. director->pushScene(scene);
  81. // demo_StartGame();
  82. return true;
  83. }
  84. // This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
  85. void AppDelegate::applicationDidEnterBackground() {
  86. Director::getInstance()->stopAnimation();
  87. // demo_applicationDidEnterBackground();
  88. }
  89. // this function will be called when the app is active again
  90. void AppDelegate::applicationWillEnterForeground() {
  91. Director::getInstance()->startAnimation();
  92. // demo_applicationWillEnterForeground();
  93. }