我不确定是我做错了还是"atlasWithDictionary“方法有问题。
我是这样使用它的:
NSArray* imageNames = @[ @"image1", @"image2", @"image3", @"image4"];
NSMutableDictionary* tempDict = [NSMutableDictionary dictionary];
for (int i = 0; i < imageNames.count; i++) {
UIImage* texture = [UIImage imageNamed:imageNames[i]];
[tempDict setObject:texture forKey:imageNames[i]];
}
SKTextureAtlas* atlasFullOfTextures = [SKTextureAtlas atlasWithDictionary:tempDict];然后在我的代码中,每当我要做
SKTexture* tex = [atlasFullOfTextures textureNamed:@"image1"];我只得到一个空对象。我做了一些故障排除,发现
NSArray* arrayOfNames = [atlasFullOfTextures textureNames];返回一个空数组。
此外,我知道图像加载得很好,因为我临时公开了字典,并成功地从UIImage对象创建了SKTextures。
有谁知道发生了什么事吗?
发布于 2014-09-25 17:40:01
字典中的关键点表示各个纹理的名称。每个键的关联对象可以是:
您没有提供图像的路径/url,您只是使用图像名称,而无法知道它们可能在哪里。您可能还必须将文件扩展名指定为Sprite Kit,它可能不会尝试猜测它。如果这些是在运行时获得或创建的纹理,它们将不在捆绑中,因此您还必须指定每个纹理的路径(通常在appdata或documents文件夹中)。
如果这些图像在捆绑包中,您可能需要指定捆绑包目录。但在这种情况下,没有理由不让Xcode在编译时创建atlas,然后使用atlasNamed:。
https://stackoverflow.com/questions/26028495
复制相似问题