- Cocos2d-x by Example:Beginner's Guide(Second Edition)
- Roger Engelbert
- 275字
- 2021-07-23 20:00:27
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 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.
- 數(shù)字媒體應(yīng)用教程
- Java高手真經(jīng)(高級編程卷):Java Web高級開發(fā)技術(shù)
- Learning SQLite for iOS
- Access 2010數(shù)據(jù)庫基礎(chǔ)與應(yīng)用項目式教程(第3版)
- 匯編語言程序設(shè)計(第3版)
- Asynchronous Android Programming(Second Edition)
- iOS開發(fā)實戰(zhàn):從入門到上架App Store(第2版) (移動開發(fā)叢書)
- jQuery炫酷應(yīng)用實例集錦
- PHP 7從零基礎(chǔ)到項目實戰(zhàn)
- Practical Predictive Analytics
- HTML5移動前端開發(fā)基礎(chǔ)與實戰(zhàn)(微課版)
- Akka入門與實踐
- Pandas入門與實戰(zhàn)應(yīng)用:基于Python的數(shù)據(jù)分析與處理
- C#程序設(shè)計基礎(chǔ)與實踐
- 秒懂算法:用常識解讀數(shù)據(jù)結(jié)構(gòu)與算法