Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since at least Cocos2d-x version 2.0.4, you can create separate subdirectories of your Resources folder and select which one to use at runtime. If a resource is not found there, Cocos2d-x will automatically fall back to the Resource folder instead of your set subdirectory. This is all described <a href="http://cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support" rel="noreferrer">here</a> in the Cocos2d-x wiki.</p> <p>As an example, you could do something like this</p> <pre><code>const CCSize winSize = CCDirector::sharedDirector()-&gt;getWinSize(); // Landscape if( winSize.height &lt; winSize.width) { if( winSize.width &gt;= 1536 ) { // iPad Retina here. CCFileUtils::sharedFileUtils()-&gt;setResourceDirectory( "iPadRetina" ); } else { // Some lower resolution tablet stuff. CCFileUtils::sharedFileUtils()-&gt;setResourceDirectory( "lowResTablet" ); } } // Portrait else { if ( winSize.width &gt;= 720 ) { // Phones like Galaxy Nexus. CCFileUtils::sharedFileUtils()-&gt;setResourceDirectory( "720" ); } else if ( winSize.width &gt;= 640 ) { // iPhone retina CCFileUtils::sharedFileUtils()-&gt;setResourceDirectory( "iPhoneRetina" ); } else { // Low res phone. CCFileUtils::sharedFileUtils()-&gt;setResourceDirectory( "lowResPhone" ); } } </code></pre> <p>You call the above code from your <code>AppDelegate::applicationDidFinishLaunching()</code> function to tell Cocos2d-x to use the correct subdirectory for resources. Let's say you have set the directory "iPhoneRetina" to be your resource directory. Then when you do</p> <pre><code>CCSprite *sprite = CCSprite::create( "cookie.png" ); </code></pre> <p>Cocos2d-x will first look for the file "iPhoneRetina/cookie.png". If it doesn't find it there, it will look for "cookie.png" in the root of your Resources folder before giving up.</p> <p>Good luck with your porting! :)</p> <p><strong>-- Edit about DPI --</strong><br> There is apparently a function <code>CCDevice::getDPI()</code> in newer versions of Cocos2d-x (user in comments suggested), I found it in version 2.1.3. However, unless you absolutely need everything to appear at the same physical size, I suggest you let the real size of things float a bit and focus on matching the resolution 1:1. If you start to scale things, they will look blurry. Also, I don't think that the same resolution at widely different screen sizes is that common. I know there are several physical sizes of screens with full HD for example, but I think all portrait ones are pretty close to each other and all tablet ones too.</p> <p>I don't know, you could of course be making an app where the physical screen size of elements in the app is very important. A measurement app where you can put things on the screen and measure them in cm or something comes to mind. If this is the case then of course the screen size of things is top priority and you might want to look into that <code>CCDevice::getDPI()</code> function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload