(original) Cocos2d-x 3.0 Sample Code Analysis 1:appdelegate

Source: Internet
Author: User

Star Month recently in using 3.0 to do similar turret game, the first time with 3.0, has been only to check the information, recently found to do some specific behavior need to understand the 3.0 of some new features. So take this opportunity to put 3.0 of the test code over again, and add comments, hope to be helpful to everyone ~

Because of the project reason, so not regularly updated ~ ~ (Small white: excuses, continue to find excuses!) )

Star Month Contribution ~ ~ ~

//AppDelegate.cpp/**************************************************************************** Copyright (c) cocos2d-x.org Copyright (c) 2013-2014 Chukong Technologies Inc.http://www.cocos2d-x.org Permission is hereby granted, free of charge, to all person obtaining a copy of this software and associated Documentatio n Files (the "Software"), to deal in the software without restriction, including without limitation the rights to use, Cop Y, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the S Oftware is furnished to does so, subject to the following conditions:the above copyright notice and this permission notice Shall is 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 and not LIMITED to the Warra Nties of merchantability, FITNESS for A particular PURPOSE and noninfringement. In NO EVENT shall the AUTHORS or COPYRIGHT holders is liable for any CLAIM, damages OR other liability, WHETHER in an ACTI On 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 (); //Release ArmatureCocostudio::armaturedatamanager::d estroyinstance ();}BOOLappdelegate::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 initializedConfiguration::getinstance ()->loadconfigfile ("configs/config-example.plist"); //Initialize DirectorAuto Director =director::getinstance (); Auto Glview= director->Getopenglview (); if(!Glview) {Glview= Glview::create ("Cpp Tests"); Director-Setopenglview (Glview); }        //Enable FPS displayDirector->setdisplaystats (true); //sets the upper FPS limit. If not set, the default FPS is capped atDirector->setanimationinterval (1.0/ -); //Get screen sizeAuto ScreenSize = glview->getframesize (); Auto Designsize= Size (480, the); Auto FileUtils=fileutils::getinstance (); Std::vector<STD::string>searchpaths; //here is the focus of implementation, compare the height of the screen and set the height of the fit, choose the right picture//then add the path of the corresponding picture to the search path, then Cocos2d-x will go to the directory to find the image    if(Screensize.height > the) {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 one level9-x on the device prevents Resolutionpolicy::no_border from working correctly//The application is visible while maintaining the aspect ratio of the original applicationGlview->setdesignresolutionsize (Designsize.width, Designsize.height, resolutionpolicy::show_all);#else    //Full screen, but may be distorted, does not maintain the aspect ratio of the original applicationGlview->setdesignresolutionsize (Designsize.width, Designsize.height, resolutionpolicy::no_border);#endif     //create a scene where the scene is a Autorelease objectAuto scene =scene::create (); //Create a layerAuto Layer =NewTestController (); #if(Cc_target_platform! = CC_PLATFORM_WP8) && (cc_target_platform! = CC_PLATFORM_WINRT)Layer-addconsoleautotest ();#endifLayer-autorelease (); //adding a layer to a sceneScene->addChild (layer); //Run the sceneDirector->runwithscene (Scene); //Enable Remote Console#if(Cc_target_platform! = CC_PLATFORM_WP8) && (cc_target_platform! = CC_PLATFORM_WINRT)//Reference http://Www.tuicool.com/articles/yauuueM//The console module has been added to Cocos2d-x version 3.0 for remote debugging. Connect the application by connecting the 5678 port on the PC, and enter the corresponding command to debug the function.Auto console = director->Getconsole (); Console->LISTENONTCP (5678);#endif    return true;}//This function was called when the app was inactive. When comes a phone call,it ' s be invoked toovoidAppdelegate::applicationdidenterbackground () {director::getinstance ()-stopanimation ();}//This function would be called when the app is active againvoidAppdelegate::applicationwillenterforeground () {director::getinstance ()-startanimation ();}//set up a test example that is now runningvoidAppdelegate::setcurrenttest (basetest*curtest) {_curtest=curtest;}//get a test example that is now runningbasetest*appdelegate::getcurrenttest () {return_curtest;}//(note: Star month's English proficiency is limited, so there may be wrong enemy, please understand) (small white: You have English over four levels ...) )

Appdelegate here to end, please look forward to the next chapter ^_^ (Small white: look forward to the yarn!) @! )

The author uses Cocos2d-x 3.0 sample code Analysis, do not reprint without the author's permission! Thank you for your mercy here ~ ~

This article does not obtain the author's own consent, may not reprint, otherwise will investigate the related responsibility. Reprint please specify the source!! ~~

Original address: http://www.cnblogs.com/wodehao0808/p/4019587.html

(original) Cocos2d-x 3.0 Sample Code Analysis 1:appdelegate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.