gpt4 book ai didi

ios - SpriteKit 有时无法加载 SKTexture

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:35 26 4
gpt4 key购买 nike

我目前在 SpriteKit 和 SKTexture 预加载方面遇到奇怪的间歇性问题。我有多个图像数组,我按以下格式预加载:

- (NSDictionary *)loadTexturesWithNames:(NSArray *)aNames
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSMutableArray *textureArray = [NSMutableArray array];

for (NSString *textureName in aNames)
{
SKTexture *texture = [SKTexture textureWithImageNamed:textureName];
if (texture)
{
[textureArray addObject:texture];
[dict setObject:texture forKey:textureName];
}
}

[SKTexture preloadTextures:textureArray withCompletionHandler:^{
_iCounter++;
[self loadTextures];
}];

return dict;
}

这在 90% 的时间里工作正常,但偶尔我会收到以下错误:

SKTexture: Error loading image resource:

这不会发生在任何特定的图像集上,只是随机发生。所以有时播放器会加载正常,而其他人则不会。这可能是内存问题吗?我使用 _iCounter 拆分纹理加载,确保前一组图像在开始下一组图像之前加载,以尝试停止过多的并发加载。这加快了进程,但我仍然看到这个间歇性问题。

有没有其他人看到过这个,或者知道是什么导致了这个?

最佳答案

根据我的经验,一个常见的原因是您没有等待调用完成处理程序。例如做这样的事情,其中​​“图像”是预加载的图像之一可能是错误的来源:

[self loadTexturesWithNames:names];
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithImageNamed:@"image"];

当然,如果您只在 loadTexture 方法中创建 Sprite 节点和纹理,应该没问题。除非您执行其他后台任务或在后台(单独的线程)运行 loadTextureWithNames 选择器。

关于ios - SpriteKit 有时无法加载 SKTexture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27292575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com