[英]SpriteKit: Using SKTextureAtlas causes incorrect Physics Body
[英]SpriteKit SKTextureAtlas atlasWithDictionary method
我不确定是否做错了此事,或者“ 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成为现实。
有人知道发生了什么吗?
从文档中 :
字典中的键代表各个纹理的名称。 每个键的关联对象可以是:
一个NSString对象,该对象包含指向包含纹理的文件的文件系统路径
NSURL对象,它包含包含纹理的文件的文件系统路径
一个UIImage对象
NSImage对象
您没有提供图像的路径/ URL,只是使用图像名称而无法告诉它们可能在哪里。 您可能还必须指定文件扩展名,因为Sprite Kit可能不会尝试猜测它。 如果这些是在运行时获取或创建的纹理,则它们将不在捆绑包中,因此您还必须指定每个纹理的路径(通常在appdata或documents文件夹中)。
如果这些图像是在捆绑,你可能要指定包目录。 但是在这种情况下,没有理由不让Xcode在编译时创建地图集,然后再使用atlasNamed:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.