3

问题是在我使用 setSearchPaths() 为不同的屏幕尺寸设置不同的图像路径后,看起来项目从图像路径随机获取图像。

例如:如果屏幕高度为 1136,则搜索路径为“iphoneBig”,项目应使用路径“iphoneBig”的图像,但有时项目使用路径“iphoneMid”的图像。

我把我的代码片段放在这里:

typedef struct tagResource

{

cocos2d::Size size;

char directory[100];

}Resource;

static Resource smallResource = { cocos2d::Size::Size(480, 320), "iphoneSmall" };

static Resource iPhone4Resource = { cocos2d::Size::Size(960, 640), "iphoneMid" };

static Resource iPhone5Resource = { cocos2d::Size::Size(1136, 640), "iphoneBig" };

cocos2d::Size frameSize = pEGLView->getVisibleSize();

pEGLView->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER);



if (frameSize.height > 960)

{

    std::string str(iPhone5Resource.directory);

    std::vector<std::string> vtStr;

    vtStr.push_back(str);

    cocos2d::FileUtils::getInstance()->setSearchPaths(vtStr);

}

else if (frameSize.height > smallResource.size.height)

{

    std::string str(iPhone4Resource.directory);

    std::vector<std::string> vtStr;

    vtStr.push_back(str);

    cocos2d::FileUtils::getInstance()->setSearchPaths(vtStr);

}

谁能告诉我原因?非常感谢。

4

1 回答 1

4

The behavior described arises from the fact that the various folders of resources have been added as groups and when Xcode creates the executable it copies all the resource files into a single path, and then identical names will be overwritten. The order in which the files are copied can make sure that the file really present in the app is different from run to run.

When you add resources to your project you have to create a folder reference (not a group) especially if more than one of the resource folders share a common filename:

enter image description here

于 2014-05-16T06:06:47.017 回答