Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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