Domanda

I would like to use cocosbuilder and cocos2d-x to develop my game for old and new iPhones. I would like to create one file for two resolutions. I created one ccb file and then I published it to retina and normal resolution. Everything works great but now I have two png files with the same name:

Published-iOS/resources-iphone/star.png

Published-iOS/resources-iphonehd/star.png

There is an issue. I am using Xcode and it doesn't like 2 files with the same name in the project. I can add these files to projects in separated groups but in final application bundle there could be only one star.png file. It is selected randomly. When I launch my app on iphone 4s I have picture from old iphone display. How to use cocosbuilder for multiple resolutions ?

È stato utile?

Soluzione

You should import the resources-iphone, and resources-iphonehd directories in your XCode project as folder references instead of groups. You can do that by drag and dropping the folders onto your XCode project. When you do that you will see the directories appearing in your applications bundle. You can check that by selecting your application's target and going to Build Phases->Copy Bundle Resources.

After that, on you ApplicationDelegate.cpp file you should add those folders in the search paths list of CCFileUtils.

std::vector<std::string> resDirOrders;

if (resolution is iphone) 
{
    resDirOrders.push_back("resources-iphone");
} 
else if (resolution is iphone retina) 
{
    resDirOrders.push_back("resources-iphonehd");
    resDirOrders.push_back("resources-iphone");
}

CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);

This is the recommended way of handling multiple resolutions according to the cocos2d-x devs (check out this article). You can use the window size from the CCDirector to determine the current resolution. In the iphonehd case I'm including the non-retina folders as well as a fallback.

Altri suggerimenti

Xcode and iOS app bundles aren't organized in folders, but rather flat bundles. You'll need to rename your files for it to work. I suggest something like this:

// iOS Standard
Published-iOS/resources-iphonehd/star@2x.png

or this

// cocos-2d Standard
Published-iOS/resources-iphonehd/star-hd.png
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top