Game Development Reference
In-Depth Information
Adding screen support for a universal app
In the previous game, we targeted iPad size screens only. Now things get a bit more com-
plicated as we add support for smaller screens in our universal game, as well as some of the
most common Android screen sizes.
So open AppDelegate.cpp . Inside the applicationDidFinishLaunching
method, we now have the following code:
auto screenSize = glview->getFrameSize();
auto designSize = Size(2048, 1536);
glview->setDesignResolutionSize(designSize.width,
designSize.height, ResolutionPolicy::EXACT_FIT);
std::vector<std::string> searchPaths;
if (screenSize.height > 768) {
searchPaths.push_back("ipadhd");
director->setContentScaleFactor(1536/designSize.height);
} else if (screenSize.height > 320) {
searchPaths.push_back("ipad");
director->setContentScaleFactor(768/designSize.height);
} else {
searchPaths.push_back("iphone");
director->setContentScaleFactor(380/designSize.height);
}
auto fileUtils = FileUtils::getInstance();
fileUtils->setSearchPaths(searchPaths);
Once again, we tell our GLView object (our OpenGL view) that we designed the game for
a certain screen size (the iPad retina screen) and once again, we want our game screen to
resize to match the screen on the device ( ResolutionPolicy::EXACT_FIT ).
Then we determine where to load our images from, based on the device's screen size. We
have art for iPad retina, then for regular iPad which is shared by iPhone retina, and for the
regular iPhone.
We end by setting the scale factor based on the designed target.
Search WWH ::




Custom Search