gpt4 book ai didi

ios - 为什么 SpriteKit 将所有设备尺寸(~ipad 和@2x~ipad)的纹理加载到内存中?

转载 作者:行者123 更新时间:2023-11-29 10:39:28 24 4
gpt4 key购买 nike

我正在使用以下代码将纹理加载到 SpriteKit 中以用于动画 -

NSMutableArray *animFrames = [NSMutableArray array];
SKTextureAtlas *animTextureAtlas = [SKTextureAtlas atlasNamed: @"bearAnimation"];

for (int i = 1; i < animTextureAtlas.textureNames.count / 3; i++) {
NSString *texture = [NSString stringWithFormat:@"image%04d", i];
[animFrames addObject:[animTextureAtlas textureNamed:texture]];
}

// This is a strong property of an NSArray where I store frames of animation
self.bearAnimationFrames = animFrames;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[SKTexture preloadTextures:self.bearAnimationFrames withCompletionHandler:^{}];
});

我的问题是,在包含视网膜 iPad、非视网膜 iPad 和视网膜 iPhone 的每个图像的三个版本的图集中使用上述代码会导致应用程序使用所有这些图像的内存。不仅仅是它需要的。

我怎样才能使加载到内存中的唯一纹理是运行应用程序的设备所需的纹理?

最佳答案

设置单独的 map 集,每种类型的屏幕一个。没有用于“加载此纹理但仅加载其中的一些位”的 SpriteKit API。

关于ios - 为什么 SpriteKit 将所有设备尺寸(~ipad 和@2x~ipad)的纹理加载到内存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25206688/

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