13, COCOS2DX 3.0 game development to find small three 3.0 director: Shimen Master, Unified Lake

Source: Internet
Author: User

the labor outcome of the re-developers. When reproduced, please be sure to indicate the source : http://blog.csdn.net/haomengzhu/article/details/27706967


Basic elements in the game

in the past article. We have specifically introduced the concept of game development and the difference between cocos2d-x and other game engines, and have even learned to differentiate itmemory management mechanism. Presumably everyone has been looking forward to exploring the world of cocos2d-x game development.


in a later article, we will combine the detailed examples from the basic elements of Cocos2d-x game development. starting from this chapter, I will be in the process of learning the engine and everyone step-by-step to create the "find small three" this game;
Director: Shimen, unified
This is a "director" in the literal sense of English, and director is the main component in controlling the game flow.

Recall that the engine framework itself generated the HelloWorld project, the last method of the game onboarding period in the program life cycle appdelegate::applicationdidfinishlaunching, and its code such as the following see:

BOOL Appdelegate::applicationdidfinishlaunching () {    ///Initialize director//Initialize Director class    Auto Director = Director:: GetInstance ();    Auto Glview = Director->getopenglview ();    if (!glview) {        Glview = glview::create (fontchina::g2u ("Shimen Lord's search Small three");        Director->setopenglview (Glview);    }    Turn on display fps//enable FPS display    Director->setdisplaystats (false);    Set FPS. The default value is 1.0/60 if you don't call this//set FPS cap. Assuming no setting, the default FPS is capped at    Director->setanimationinterval (1.0/60);    Create a scene. It's an Autorelease object//Create a scene where the scene is a Autorelease object    auto scene = Helloworld::createscene ();    Run//execution scene    director->runwithscene (scene);    return true;}

can see. In fact, the director's work is really similar to the work of the directors. The Director class is primarily responsible for the following work. 1, the game rendering aspects of the settings, including setting the game rendering of the form, FPS display, the default frame rate limit, texture color bit width and so on.

2. Toggle the current game scene, pause or resume the execution of the game scene.

All in all, the game is under the management of the Director of the presentation setup and Process Control.


Director plays the role of the martial arts, so it is very natural to use a single example of the design pattern, that is, the whole martial arts in this one.


throughout the martial arts 、、、、 Oh, no, no matter where in the program, can be through the following simple code access to: Auto Director = Director::getinstance ();
In the Director. The following methods for managing scenarios are also defined.

Runwithscene (scene* Scene): Launches the game and executes scene scenes.

This method is called when the primary scene is first started when the main program starts.
replacescene (scene* scene): Toggles the scene by replacing the current scene directly with the incoming scene, and the current scenario is released. This is the most frequently used method when switching scenes.


Pushscene (scene* Scene): Pauses the currently executing scene and presses it into the generation execution scenario stack. The incoming scene is then set to the current execution scenario.


Popscene: Releases the current scene. Then pops the top of the stack from the generation execution scenario stack. and set it as the current execution scenario. If the stack is empty, the direct endapplication. Used in pairs with pushscene. Able to reach the shape of the main interface into the Setup interface, and then return to the main interface effect.
Pause : Pauses all timers and actions in the current execution scene, and the scene still appears on the screen.
Resume : Resumes paused timers and actions in the current execution scene. It is used in conjunction with pause.
End : Ends the scene and exits the app at the same time.
It is important to note that the above three ways of switching scenes (Replacescene, Pushscene, popscene) are all loaded with the scene to be switchedafter completion, the current execution of the scene is released. So, in the new scene, it just completely loads into the finished moment. There are two scenarios at the same time in the system, which will beinsidea test, if you are not careful, switching scenes can cause memory shortages.
For many other functions of ps:director, please refer to: cocos\2d\ccdirector.h


Shimen Main Friendship tips:The game found the small three, but in reality do not go to find 、、、

13, COCOS2DX 3.0 game development to find small three 3.0 director: Shimen Master, Unified Lake

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.