如何从资源
问题描述:
您好,我在我的代码创建了一个新组的子文件夹中加载图像,并把所有的图像,现在资源\ CountryFlags是我这样做如何从资源
NSString *fileName = countryInfo.ImageUrl;
CCSprite *flag ;
NSString * fullPath = [[NSBundle mainBundle] pathForResource: [fileName stringByDeletingPathExtension]
ofType: [fileName pathExtension]
inDirectory: @"CountryFlags"];
if (fullPath)
{
UIImage *theImage = [UIImage imageWithContentsOfFile: fullPath];
if (theImage)
{
flag = [CCSprite spriteWithCGImage: [theImage CGImage] key: fileName];
flag.position = ccp(200, 265);
flag.scale = .255;
}
}
但FULLPATH总是得到零路径并没有得到代码,所以任何人都不知道如何解决这个问题
答
我想这是因为你的应用程序捆绑包中没有“CountryFlags”文件夹。 XCode不会复制资源的目录结构,除非将文件夹添加为文件夹引用(项目导航器中的蓝色文件夹图标,而不是黄色)。