(原創)cocos2d-x 3.0 範例程式碼分析1:AppDelegate

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   使用   ar   

星月最近在用3.0做類似刀塔遊戲,第一次用3.0,之前一直只是查查資料,最近發現做一些特定行為需要對3.0一些新的特性瞭解。所以趁這個機會,把3.0的測試代碼過一遍,同時增加註釋,希望能對大家有協助~

因為項目原因,所以不定期更新~~(小白:借口,繼續找借口!)

 

星月傾心貢獻~~~

 

// AppDelegate.cpp/**************************************************************************** Copyright (c) 2013      cocos2d-x.org Copyright (c) 2013-2014 Chukong Technologies Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/#include "AppDelegate.h"#include "cocos2d.h"#include "controller.h"#include "cocostudio/CocoStudio.h"#include "extensions/cocos-ext.h"USING_NS_CC;AppDelegate::AppDelegate():_curTest(nullptr){}AppDelegate::~AppDelegate(){//    SimpleAudioEngine::end();    // 釋放armature    cocostudio::ArmatureDataManager::destroyInstance();}bool AppDelegate::applicationDidFinishLaunching(){    // As an example, load config file    // XXX: This should be loaded before the Director is initialized,    // XXX: but at this point, the director is already initialized    Configuration::getInstance()->loadConfigFile("configs/config-example.plist");    // initialize director    auto director = Director::getInstance();    auto glview = director->getOpenGLView();    if(!glview) {        glview = GLView::create("Cpp Tests");        director->setOpenGLView(glview);    }        // 啟用 FPS 顯示    director->setDisplayStats(true);        // 設定 FPS 上限。如果不加設定,則預設 FPS 上限為 60    director->setAnimationInterval(1.0 / 60);        // 擷取螢幕尺寸    auto screenSize = glview->getFrameSize();    auto designSize = Size(480, 320);    auto fileUtils = FileUtils::getInstance();    std::vector<std::string> searchPaths;        // 這裡是實現的重點,比較螢幕的高和設定的適配尺寸的高,選擇合適的圖片    // 然後將對應圖片的路徑添加到搜尋路徑中,那麼cocos2d-x就會到該目錄去尋找圖片    if (screenSize.height > 320)    {        auto resourceSize = Size(960, 640);        searchPaths.push_back("hd");        searchPaths.push_back("hd/scenetest");        searchPaths.push_back("hd/scenetest/ArmatureComponentTest");        searchPaths.push_back("hd/scenetest/AttributeComponentTest");        searchPaths.push_back("hd/scenetest/BackgroundComponentTest");        searchPaths.push_back("hd/scenetest/EffectComponentTest");        searchPaths.push_back("hd/scenetest/LoadSceneEdtiorFileTest");        searchPaths.push_back("hd/scenetest/ParticleComponentTest");        searchPaths.push_back("hd/scenetest/SpriteComponentTest");        searchPaths.push_back("hd/scenetest/TmxMapComponentTest");        searchPaths.push_back("hd/scenetest/UIComponentTest");        searchPaths.push_back("hd/scenetest/TriggerTest");        director->setContentScaleFactor(resourceSize.height/designSize.height);    }    else    {        searchPaths.push_back("scenetest/ArmatureComponentTest");        searchPaths.push_back("scenetest/AttributeComponentTest");        searchPaths.push_back("scenetest/BackgroundComponentTest");        searchPaths.push_back("scenetest/EffectComponentTest");        searchPaths.push_back("scenetest/LoadSceneEdtiorFileTest");        searchPaths.push_back("scenetest/ParticleComponentTest");        searchPaths.push_back("scenetest/SpriteComponentTest");        searchPaths.push_back("scenetest/TmxMapComponentTest");        searchPaths.push_back("scenetest/UIComponentTest");        searchPaths.push_back("scenetest/TriggerTest");    }        fileUtils->setSearchPaths(searchPaths);#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)    // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly    // 應用程式可見,同時保持原始應用程式的寬高比    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL); #else    // 鋪滿全屏,但是可能會失真,不保持原始應用程式的寬高比    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);#endif     // 建立一個情境,情境是一個 autorelease 對象    auto scene = Scene::create();        // 建立圖層    auto layer = new TestController();    #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)    layer->addConsoleAutoTest();#endif    layer->autorelease();    // 將圖層加入到情境中    scene->addChild(layer);        // 運行情境    director->runWithScene(scene);    // Enable Remote Console#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)    // 參考資料http://www.tuicool.com/articles/yauuueM    // 在Cocos2d-x 3.0 版新增了Console模組,可實現遠端偵錯。在PC上串連5678連接埠,即可串連應用程式,輸入對應的命令進行調試功能.    auto console = director->getConsole();    console->listenOnTCP(5678);#endif    return true;}// This function will be called when the app is inactive. When comes a phone call,it‘s be invoked toovoid AppDelegate::applicationDidEnterBackground(){    Director::getInstance()->stopAnimation();}// this function will be called when the app is active againvoid AppDelegate::applicationWillEnterForeground(){    Director::getInstance()->startAnimation();}// 設定現在正在啟動並執行測試例void AppDelegate::setCurrentTest(BaseTest* curTest){    _curTest = curTest;}// 獲得現在正在啟動並執行測試例BaseTest* AppDelegate::getCurrentTest(){    return _curTest;}// (註:星月的英語水平有限,所以可能有錯誤的敵方,請大家諒解)(小白:你英語過四級了嗎...)

AppDelegate到這裡結束,敬請期待下一章節^_^(小白:期待毛線!@!)

作者使用 cocos2d-x 3.0 範例程式碼分析,未經作者允許,請勿轉載!在此謝謝各位手下留情~~~

本文沒有獲得作者本人同意,不得轉載,否則必追究相關責任。轉載請註明出處!!~~

原文地址:http://www.cnblogs.com/wodehao0808/p/4019587.html

(原創)cocos2d-x 3.0 範例程式碼分析1:AppDelegate

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.