Imitation "Thunder Fighter" flying shooter Tour development--the game's entrance

Source: Internet
Author: User

Entrance to the game Appdelegate

After the game starts, the first instantiation is the Appdelegate class, which we need to modify two functions: Applicationdidfinishlaunching and Applicationdidenterbackground.

First introduced applicationdidfinishlaunching (), the game started, the first entry is this method, here, we can set the game resolution, frame rate, the third-party SDK initialization, and the first time to appear in the scene.

1 BOOLappdelegate::applicationdidfinishlaunching ()2 {3Auto Director =director::getinstance ();4Auto Glview = director->Getopenglview ();5     if(!Glview) {6         //To define the size of a window running under Windows7Glview = Glviewimpl::createwithrect ("Raiden",8Rect (0,0, CONSTANT::D esign_res_width * constant::res_ratio, CONSTANT::D esign_res_height *constant::res_ratio));9Director->Setopenglview (glview);Ten     } One  A     //selecting different zoom modes for horizontal and vertical screens -Auto Framesize = glview->getframesize (); -     if(Framesize.width >=framesize.height) the     { -Director->getopenglview ()setdesignresolutionsize (CONSTANT::D esign_res_width, CONSTANT::D esign_res_height, Resolutionpolicy::show_all) ; -     } -     Else +     { -Director->getopenglview ()setdesignresolutionsize (CONSTANT::D esign_res_width, CONSTANT::D esign_res_height, resolutionpolicy::exact_ FIT); +     } A  at     //set the frame rate to 60 frames per second -Director->setanimationinterval (1.0f/ -); -     //set the search path -Fileutils::getinstance ()->addsearchpath ("Res"); -  -     //Create the first scene to enter inAuto scene =Loadinglayer::scene (); -  to     //Enter the scene +Director->runwithscene (scene); -     //initializing a third-party SDK theBmobsdkinit::initialize ("app_id","App_key"); *  $     return true;Panax Notoginseng}

Here are a few things to keep in mind:

Create Windows window
Glview = Glviewimpl::createwithrect ("Raiden", Rect (0, 0, CONSTANT::D esign_res_width * constant::res_ratio, CONSTANT::D Esign_res_height * constant::res_ratio));

This is to create a window to run under Windows. For debugging convenience, when we develop the game, we will compile the debugging in Windows, wait until the Windows version debugging pass, and then compile the Android version. Rect (0, 0, CONSTANT::D esign_res_width * constant::res_ratio, CONSTANT::D esign_res_height * constant::res_ratio) Defines the size of the window, where several macros are defined as follows:

Const float design_res_width = 540;    Width Const float design_res_height = 960;   Height const float Res_ratio = 0.75f;

Because my notebook height is less than 960, so here use Res_ratio to do the same scale reduction. If the window does not shrink, then the game window will be displayed incomplete, and more serious, there will be a mouse click to locate the problem.

Zoom mode

We used the Setdesignresolutionsize function to set the zoom mode, where the Resolutionpolicy value range is as follows:

    • Resolutionpolicy::show_all screen width, height, and design resolution wide, high computational scaling factor, take (small) as a wide, high scaling factor. Ensure that the design area is all displayed on the screen, but there may be black edges.
    • Resolutionpolicy::exact_fit screen width and design aspect ratio as the scaling factor in the x direction, the screen height and the design height ratio as the scaling factor in the y direction. The design area is guaranteed to fully fill the screen, but image stretching may occur.
    • Resolutionpolicy::no_border screen width, height, and design resolution wide, high computational scaling factor, take the larger (large) as a wide, high scaling factor. Ensures that the design area is always covered in one direction, while the other is generally outside the screen area.
    • Both the Resolutionpolicy::fixed_height and Resolutionpolicy::fixed_width are internally corrected for incoming design resolution to ensure screen resolution to the design resolution without stretching the full screen.

In this program, we know the current horizontal or vertical screen according to the width of the screen. If it is a vertical screen, the exact_fit is used to ensure full-screen mode without black edges, and if it is a horizontal screen, Show_all is used to prevent the game interface from scaling.

The processing logic of the game into the background

The Applicationdidenterbackground () function is triggered when a user calls or presses the home key to make the game enter the background.

void Appdelegate::applicationdidenterbackground () {    director::getinstance (),stopanimation ();     // determines whether the game is currently in play, and if so, pauses    the game planelayer* Pplanelayer = dynamic_cast<planelayer*>(Gamelayer::getplanelayer ());    Hublayer* Phublayer = dynamic_cast(Gamelayer::gethublayer ());     if (Phublayer && pplanelayer &&!pplanelayer->ispause ())    {        Phublayer-Menupausecallback (nullptr);    }}

All we need to know here is that we did the action of pausing the game, namely Menupausecallback, when the game pops up and pauses the scene. Some of the classes and methods in the above functions, which we'll talk about later.

Download Source code

Next, we will enter into the Loadinglayer class to explore the game resource onboarding mechanism

Imitation "Thunder Fighter" flying shooter Tour development--the game's entrance

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: 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.