Time for action – adding retina support
This time we'll work with the class AppDelegate.cpp
:
- Go to
AppDelegate.cpp
(you'll find it in theClasses
folder). Inside theapplicationDidFinishLaunching
method, and below thedirector->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);
- 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...