官术网_书友最值得收藏!

  • Cocos2d-x Cookbook
  • Akihiro Matsuura
  • 303字
  • 2021-07-09 20:58:47

Preparing your original game

In the next chapter, we will start the original game. You know there are a lot of comments and codes in HelloWorldScene.cpp and the HelloWorldScene.h file. That's why we will remove unnecessary codes in the template project and get started with the original game right away.

How to do it…

  1. Open HelloWorldScene.h and remove the menuCloseCallback method and unnecessary comments. Now HelloWorldScene.h should look like the following code:
     #ifndef __HELLOWORLD_SCENE_H__
       #define __HELLOWORLD_SCENE_H__
       #include "cocos2d.h" 
    
       class HelloWorld : public cocos2d::Layer
       { 
    public:
        static cocos2d::Scene* createScene();
        virtual bool init();
        CREATE_FUNC(HelloWorld);
    };
    #endif // __HELLOWORLD_SCENE_H__
  2. The next step is to open HelloWorldScene.cpp and remove unnecessary comments, codes, and methods. Now HelloWorldScene.cpp should look like the following code:
    #include "HelloWorldScene.h"
    USING_NS_CC; 
    Scene* HelloWorld::createScene()
    {
        auto scene = Scene::create();
        auto layer = HelloWorld::create();
        scene->addChild(layer);
        return scene;
    } 
    bool HelloWorld::init()
    {
        if ( !Layer::init() )
        {
            return false;
        }
        return true;
    }
  3. The next step is to remove unnecessary images in resources. Remove CloseNormal.png, CloseSelected.png and HelloWorld.png from the Resources folder in Xcode:
    How to do it…
  4. Finally, if you are developing only iOS and Android applications, you don't need files for other platforms such as Linux, Windows, and Windows Phone. You should remove these files.

    Before removing platform files, it should look like the following screenshot:

    How to do it…

    After removing platform files, it should look like the following screenshot:

    How to do it…

How it works…

With this recipe, you can get the simplest project ready before removing unnecessary comments, codes, and methods. Removing unnecessary platform codes and resources is important for reducing the size of your application. If you start building your original game from scratch, you will need to follow this recipe or chances are, you may get a black screen if you build and run this project. In the next chapter, you can start coding within this simple project.

主站蜘蛛池模板: 衡东县| 博客| 临高县| 岳普湖县| 外汇| 安义县| 长汀县| 江油市| 怀宁县| 拉萨市| 南丰县| 新营市| 枝江市| 抚松县| 临沧市| 三明市| 阳春市| 张家川| 济阳县| 庆城县| 西昌市| 顺义区| 涪陵区| 岐山县| 丰原市| 长顺县| 合作市| 密云县| 塘沽区| 巧家县| 特克斯县| 文化| 麦盖提县| 北京市| 洛南县| 闻喜县| 阳高县| 张家口市| 武川县| 永寿县| 邵阳市|