AppDelegate.cpp 3.9 KB

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