Browse Source

Arrumando appdelegate

capellaresumo 6 years ago
parent
commit
ef0bc060ab

+ 30 - 56
Classes/AppDelegate.cpp

@@ -1,20 +1,16 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   AppDelegate.cpp
+ *  Descrição: Classe para inicializar jogo. Padrão da biblioteca.
+ ********************************************************************/
+
 #include "AppDelegate.h"
 #include "BeginScene.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;
 
@@ -24,15 +20,9 @@ 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};
@@ -50,72 +40,56 @@ bool AppDelegate::applicationDidFinishLaunching() {
     auto director = Director::getInstance();
     auto glview = director->getOpenGLView();
     if(!glview) {
-#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
-    director->setContentScaleFactor(2);
-    glview = GLViewImpl::createWithRect("RedCore", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
-#else
+
+        // Personaliza para descktop
+        #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
+        director->setContentScaleFactor(2);
+        glview = GLViewImpl::createWithRect(
+            "RedCore",
+            cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height)
+        );
+        #else
         glview = GLViewImpl::create("RedCore");
-#endif
+        #endif
+
         director->setOpenGLView(glview);
     }
 
     // turn on display FPS
-#if DEBUG
+    #if DEBUG
     director->setDisplayStats(true);
-#endif
+    #endif
 
     // set FPS. the default value is 1.0/60 if you don't call this
     director->setAnimationInterval(1.0f / 60);
 
     // Set the design resolution
-    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
-    auto frameSize = glview->getFrameSize();
-    // if the frame's height is larger than the height of medium size.
-    // if (frameSize.height > mediumResolutionSize.height)
-    // {        
-    //     director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
-    // }
-    // // if the frame's height is larger than the height of small size.
-    // else if (frameSize.height > smallResolutionSize.height)
-    // {        
-    //     director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
-    // }
-    // // if the frame's height is smaller than the height of medium size.
-    // else
-    // {        
-    //     director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
-    // }
-    
+    glview->setDesignResolutionSize(
+        designResolutionSize.width,
+        designResolutionSize.height,
+        ResolutionPolicy::NO_BORDER
+    );
 
     register_all_packages();
 
-
     Scene* scene = BeginScene::createScene();
     director->runWithScene(scene);
 
     return true;
 }
 
-// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
+/** 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
 }

+ 34 - 32
Classes/AppDelegate.h

@@ -1,40 +1,42 @@
+/********************************************************************
+ *  Nomes: Gabriel Capella                       Números USP: 8962078 
+ *         João Herique Luciano                               8535957
+ * 
+ *  Tarefa:    RedCore - EP2 MAC0463
+ *  Arquivo:   AppDelegate.h
+ *  Descrição: Classe para inicializar jogo. Padrão da biblioteca.
+ ********************************************************************/
+
 #ifndef  _APP_DELEGATE_H_
 #define  _APP_DELEGATE_H_
 
 #include "cocos2d.h"
 
-/**
-@brief    The cocos2d Application..
-
-Private inheritance here hides part of interface from Director.
-*/
-class  AppDelegate : private cocos2d::Application
-{
-public:
-    AppDelegate();
-    virtual ~AppDelegate();
-
-    virtual void initGLContextAttrs();
-
-    /**
-    @brief    Implement Director and Scene init code here.
-    @return true    Initialize success, app continue.
-    @return false   Initialize failed, app terminate.
-    */
-    virtual bool applicationDidFinishLaunching();
-
-    /**
-    @brief  Called when the application moves to the background
-    @param  the pointer of the application
-    */
-    virtual void applicationDidEnterBackground();
-
-    /**
-    @brief  Called when the application reenters the foreground
-    @param  the pointer of the application
-    */
-    
-    virtual void applicationWillEnterForeground();
+class  AppDelegate : private cocos2d::Application {
+    public:
+        AppDelegate();
+        virtual ~AppDelegate();
+
+        virtual void initGLContextAttrs();
+
+        /**
+        @brief    Implement Director and Scene init code here.
+        @return true    Initialize success, app continue.
+        @return false   Initialize failed, app terminate.
+        */
+        virtual bool applicationDidFinishLaunching();
+
+        /**
+        @brief  Called when the application moves to the background
+        @param  the pointer of the application
+        */
+        virtual void applicationDidEnterBackground();
+
+        /**
+        @brief  Called when the application reenters the foreground
+        @param  the pointer of the application
+        */
+        virtual void applicationWillEnterForeground();
 };
 
 #endif // _APP_DELEGATE_H_

+ 6 - 1
README.md

@@ -17,4 +17,9 @@ Para montar o APK do jogo:
 
 Esse script vai fazer o download do cocos2d-x (por volta de 350mb).
 
-Quando uma raquete muda de tamanho, ela volta ao seu tamho original depois de certo tempo.
+Quando uma raquete muda de tamanho, ela volta ao seu tamho original depois de certo tempo.
+
+Politica de redimencionamento.
+
+No border policy will scale proportionally the container so that it fills up the entire frame. In this case, if the width/height ratio of the frame doesn't equal to your designed ratio, some area of your game will be cut off. In the meantime, under no border policy, cc.visibleRect represent the viewport of canvas in the game world, and it can be smaller than cc.winSize.
+

BIN
proj.ios_mac/RedCore.xcodeproj/project.xcworkspace/xcuserdata/capella.xcuserdatad/UserInterfaceState.xcuserstate