text: ﻿#include "AppDelegate.h"
  #include "HelloWorldScene.h"
  
  // #define USE_AUDIO_ENGINE 1
  // #define USE_SIMPLE_AUDIO_ENGINE 1
  
  #if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
  #error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
  #endif
  
  #if USE_AUDIO_ENGINE
  #include "audio/include/AudioEngine.h"
  using namespace cocos2d::experimental;
  #elif USE_SIMPLE_AUDIO_ENGINE
  #include "audio/include/SimpleAudioEngine.h"
  using namespace CocosDenshion;
  #endif
  
  USING_NS_CC;
  
  static cocos2d::Size designResolutionSize = cocos2d::Size(320, 480);
  static cocos2d::Size smallResolutionSize = cocos2d::Size(320, 480);
  static cocos2d::Size mediumResolutionSize = cocos2d::Size(640, 960);
  static cocos2d::Size largeResolutionSize = cocos2d::Size(1536, 2048);
  
  AppDelegate::AppDelegate()
  {
  }
  
  AppDelegate::~AppDelegate() 
  {
  #if USE_AUDIO_ENGINE
      AudioEngine::end();
  #elif USE_SIMPLE_AUDIO_ENGINE
      SimpleAudioEngine::end();
  #endif
  }
  
  // if you want a different context, modify the value of glContextAttrs
  // it will affect all platforms
  void AppDelegate::initGLContextAttrs()
  {
      // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
      GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  
      GLView::setGLContextAttrs(glContextAttrs);
  }
  
  // if you want to use the package manager to install more packages,  
  // don't modify or remove this function
  static int register_all_packages()
  {
      return 0; //flag for packages manager
  }
  
  bool AppDelegate::applicationDidFinishLaunching() {
  	// initialize director
  	auto director = Director::getInstance();
  	auto glview = director->getOpenGLView();
  	if (!glview) {
  		glview = GLViewImpl::create("My Game");
  		glview->setFrameSize(320, 480);
  		director->setOpenGLView(glview);
  	}
  
  	// turn on display FPS
  	director->setDisplayStats(false);
  
  	// set FPS. the default value is 1.0/60 if you don't call this
  	director->setAnimationInterval(1.0 / 60);
  
  	//屏幕大小
  	auto screenSize = glview->getFrameSize();
  	//设计分辨率大小
  	auto designSize = Size(320, 480);
  	//资源大小
  	auto resourceSize = Size(640, 960);
  
  	//std::vector<std::string> searchPaths;
  
  	director->setContentScaleFactor(resourceSize.width / designSize.width); //默认为1.0f
  
  //#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  //	if (screenSize.height > 960) {	//640x1136
  //		designSize = Size(320, 568);
  //		searchPaths.push_back("hd");
  //	}
  //	else {
  //		searchPaths.push_back("hd");
  //	}
  //	FileUtils::getInstance()->setSearchPaths(searchPaths);
  //#else
  //	FileUtils::getInstance()->addSearchPath(FileUtils::getInstance()->getWritablePath());
  //	std::vector<std::string> searchpath;
  //	searchpath.push_back(FileUtils::getInstance()->getWritablePath() + "hd");
  //	FileUtils::getInstance()->setSearchPaths(searchpath);
  //#endif
  	
  	glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_WIDTH);
  
  	// create a scene. it's an autorelease object
  	auto scene = HelloWorld::createScene();
  
  	// run
  	director->runWithScene(scene);
  
  
  	return true;
  }
  
  // This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
  void AppDelegate::applicationDidEnterBackground() {
      Director::getInstance()->stopAnimation();
  
  #if USE_AUDIO_ENGINE
      AudioEngine::pauseAll();
  #elif USE_SIMPLE_AUDIO_ENGINE
      SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
      SimpleAudioEngine::getInstance()->pauseAllEffects();
  #endif
  }
  
  // this function will be called when the app is active again
  void AppDelegate::applicationWillEnterForeground() {
      Director::getInstance()->startAnimation();
  
  #if USE_AUDIO_ENGINE
      AudioEngine::resumeAll();
  #elif USE_SIMPLE_AUDIO_ENGINE
      SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
      SimpleAudioEngine::getInstance()->resumeAllEffects();
  #endif
  }
  