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

Time for action – adding retina support

This time we'll work with the class AppDelegate.cpp:

  1. Go to AppDelegate.cpp (you'll find it in the Classes folder). Inside the applicationDidFinishLaunching method, and below the director->setAnimationInterval(1.0 / 60) line, add the following lines:
    auto screenSize = glview->getFrameSize();
    auto designSize = Size(768, 1024);
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::EXACT_FIT);
    
    std::vector<std::string> searchPaths;
    if (screenSize.width > 768) {
        searchPaths.push_back("hd");
        director->setContentScaleFactor(2);
    } else  {
        searchPaths.push_back("sd");
        director->setContentScaleFactor(1);
    }
    auto fileUtils = FileUtils::getInstance();
    fileUtils->setSearchPaths(searchPaths);
  2. Save the file.

What just happened?

An entire book could be written about this topic, although in this first example, we have a very simple implementation on how to support multiple screen sizes since we are only targeting iPads. Here we are saying: "Hey AppDelegate, I designed this game for a 768 x 1024 screen."

All the values for positioning and font size were chosen for that screen size. If the screen is larger, make sure you grab the files from the hd folder and change the scale by which you will multiply all my positioning and font sizes. If the screen has the same size I designed the game for, use the files in the sd folder and set the scale to 1. (Android adds even more complexity to this, but we'll tackle that in later in the book.)

FileUtils will look for every file you load for your game first inside Resources | sd (or hd). If it doesn't find them there, it will try to find them in Resources. This is a good thing because files shared by both versions may be added only once to the project, inside Resources. That is what we'll do now with the sound files.

主站蜘蛛池模板: 丽江市| 崇仁县| 富民县| 墨玉县| 招远市| 阿合奇县| 招远市| 江山市| 陕西省| 博乐市| 三河市| 贵溪市| 西乌珠穆沁旗| 怀安县| 水富县| 合川市| 邵武市| 阳谷县| 桃源县| 贵溪市| 奇台县| 西平县| 龙山县| 陆川县| 酉阳| 普安县| 巴林右旗| 乌鲁木齐市| 怀集县| 三门县| 锡林浩特市| 浮梁县| 桦南县| 保定市| 大同市| 罗田县| 安乡县| 章丘市| 抚州市| 巧家县| 余干县|