AppDelegate.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /********************************************************************
  2. * Nomes: Gabriel Capella Números USP: 8962078
  3. * João Herique Luciano 8535957
  4. *
  5. * Tarefa: RedCore - EP2 MAC0463
  6. * Arquivo: AppDelegate.cpp
  7. * Descrição: Classe para inicializar jogo. Padrão da biblioteca.
  8. ********************************************************************/
  9. #include "AppDelegate.h"
  10. #include "BeginScene.h"
  11. #include "audio/include/SimpleAudioEngine.h"
  12. using namespace CocosDenshion;
  13. USING_NS_CC;
  14. static cocos2d::Size designResolutionSize = cocos2d::Size(1080/2, 1920/2);
  15. AppDelegate::AppDelegate() {
  16. }
  17. AppDelegate::~AppDelegate() {
  18. SimpleAudioEngine::end();
  19. }
  20. void AppDelegate::initGLContextAttrs() {
  21. // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
  22. GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  23. GLView::setGLContextAttrs(glContextAttrs);
  24. }
  25. // if you want to use the package manager to install more packages,
  26. // don't modify or remove this function
  27. static int register_all_packages() {
  28. return 0; //flag for packages manager
  29. }
  30. bool AppDelegate::applicationDidFinishLaunching() {
  31. // initialize director
  32. auto director = Director::getInstance();
  33. auto glview = director->getOpenGLView();
  34. if(!glview) {
  35. // Personaliza para descktop
  36. #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
  37. director->setContentScaleFactor(2);
  38. glview = GLViewImpl::createWithRect(
  39. "RedCore",
  40. cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height)
  41. );
  42. #else
  43. glview = GLViewImpl::create("RedCore");
  44. #endif
  45. director->setOpenGLView(glview);
  46. }
  47. // turn on display FPS
  48. #if DEBUG
  49. director->setDisplayStats(true);
  50. #endif
  51. // set FPS. the default value is 1.0/60 if you don't call this
  52. director->setAnimationInterval(1.0f / 60);
  53. // Set the design resolution
  54. glview->setDesignResolutionSize(
  55. designResolutionSize.width,
  56. designResolutionSize.height,
  57. ResolutionPolicy::NO_BORDER
  58. );
  59. register_all_packages();
  60. Scene* scene = BeginScene::createScene();
  61. director->runWithScene(scene);
  62. return true;
  63. }
  64. /** This function will be called when the app is inactive. Note, when
  65. * receiving a phone call it is invoked.
  66. * */
  67. void AppDelegate::applicationDidEnterBackground() {
  68. Director::getInstance()->stopAnimation();
  69. SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
  70. SimpleAudioEngine::getInstance()->pauseAllEffects();
  71. }
  72. // this function will be called when the app is active again
  73. void AppDelegate::applicationWillEnterForeground() {
  74. Director::getInstance()->startAnimation();
  75. SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
  76. SimpleAudioEngine::getInstance()->resumeAllEffects();
  77. }