Cocos2dx[3.x] (5)--Entrance class AppDelegate.cpp

Source: Internet
Author: User

Nagging

The entry class AppDelegate.cpp is the entry for the game program.



"AppDelegate.cpp"


This is the entry of the game program, mainly used for the logic initialization of the game program, and create the entry interface (i.e. the first game interface scene) to run the program.

There are three methods:

Applicationdidfinishlaunching ();  Logical initialization of applicationdidenterbackground (); Switch to Background applicationwillenterforeground (); Switch to front desk//

Source Analysis:

Bool appdelegate::applicationdidfinishlaunching ()  {//initialize a director,  can only have one Director auto director  = director::getinstance ();//Use Openglviewauto glview = director->getopenglview (); Glview)  {glview = glview::create ("My game"); Glview->setframesize (480, 320);// program window title Director->setopenglview (Glview);} Screen Fit, set the game design resolution glview->setdesignresolutionsize (480, 320, resolutionpolicy::show_all);//Open status display,   Number of frames, number of sprites, etc. director->setdisplaystats (true);//refresh frequency, 60 frames per second. Director->setanimationinterval (1.0 / 60);//Create a scene HelloWorld, which is the first interface of a game program auto scene =  helloworld::createscene ();//Run Director->runwithscene (scene); return true;}   Switch to Background void appdelegate::applicationdidenterbackground ()  {//pause Game director::getinstance (), StopAnimation ();//Pause Music simpleaudioengine::getinstance ()->pausebackgroundmusic ();}   Switch to front void appdelegate::applicationwillenterforeground ()  {//continue gameDirector::getinstance ()->startanimation ();//Continue Music simpleaudioengine::getinstance ()->resumebackgroundmusic ( );} //


In this case, you may be confused. Why is the resolution size set two times?

setframesize (480,);

setdesignresolutionsize (480,320,resolutionpolicy::show_all);

Friends, the meaning of these two is not the same drop.

setdesignresolutionsize is to set the resolution of our game design, that is, to fit the width of 480 high 320 screen scale. That is, the designer's original game resolution screen size. But for each user, the device they use is not necessarily (480,320), for example, the phone has a lot of small. The resolutionpolicy::show_all parameter in the back means that the original scale (480/320) is scaled to fit the actual screen of the device.

setframesize (480,) sets the screen size of the device we expect, which is the size of the application window.


Here are a few contrast charts to deepen your understanding.

1, this is the original image size, the window size is 480 * 320.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/C8/wKiom1PrKH3CcRIOAAD_nAYof-Q636.jpg "title=" 1.jpg " alt= "Wkiom1prkh3ccrioaad_nayof-q636.jpg" style= "float:none;"/>


2, if the window size is set to setframesize (960, 640), without setting the design resolution scaling ratio Resolutionpolicy::show_all , the picture does not shrink, the original image is still 480 * 320.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/C9/wKioL1PrKZbAgMrIAAFr7Y9wj5U764.jpg "title=" 2.jpg " alt= "Wkiol1prkzbagmriaafr7y9wj5u764.jpg" style= "float:none;"/>


3, after setting the resolutionpolicy::show_all , the picture is shrunk to fit the entire screen 960 * 640.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/C8/wKiom1PrKH2BVTStAALbxOSia9g185.jpg "title=" 3.jpg " alt= "Wkiom1prkh2bvtstaalbxosia9g185.jpg" style= "float:none;"/>



This article is from the "Summer Wind" blog, please be sure to keep this source http://shahdza.blog.51cto.com/2410787/1550087

Cocos2dx[3.x] (5)--Entrance class AppDelegate.cpp

Related Article

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.