Sprite kit .png动画在spritekit中表现缓慢

Sprite kit .png动画在spritekit中表现缓慢,sprite-kit,Sprite Kit,我的项目中有一个.png动画,有700张图片,大小为150像素x 150像素 它工作正常,但每次动画开始时,整个游戏都会冻结约0.1秒。喜欢它的加载,但我在initWithSize中实现了.png数组。像这样: SKTextureAtlas *barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"]; NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNa

我的项目中有一个.png动画,有700张图片,大小为150像素x 150像素

它工作正常,但每次动画开始时,整个游戏都会冻结约0.1秒。喜欢它的加载,但我在initWithSize中实现了.png数组。像这样:

SKTextureAtlas *barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"];
NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNames];
NSArray *sortetBarrierUfoAtlasNames = [barrierUfoAtlasNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableArray *barrierUfoTextures = [NSMutableArray array];

for (NSString *filename in sortetBarrierUfoAtlasNames) {
    SKTexture *texture = [barrierUfoAtlas textureNamed:filename];
    [barrierUfoTextures addObject:texture];
}
self.barrierUfoAnimation = [SKAction animateWithTextures:barrierUfoTextures timePerFrame:0.024];
然后在大约1-2分钟后播放。动画开始。 此时不需要加载任何内容,只需启动动画即可。
有什么方法可以改进吗?

这是许多预加载方法之一:

@implementation GameScene {
SKTextureAtlas *myAtlas1;
BOOL loadingComplete;
}

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {

    // the usual stuff...

    loadingComplete = false;
    [self loadMyAtlas1];
    }   

    return self;
}

-(void)loadMyAtlas1 {
    myAtlas1 = [SKTextureAtlas atlasNamed:@"MyAtlasName"];
    [SKTextureAtlas preloadTextureAtlases:[NSArray arrayWithObject:myAtlas1] withCompletionHandler:^{
    [self finishedLoading];
    }];
}

-(void)finishedLoading {
    // other stuff you might do here
    loadingComplete = true;
}

-(void)update:(CFTimeInterval)currentTime {
    if(loadingComplete) {
        // run game code
    } else {
        // wait for the water to boil
    }
}

您可以在加载所有游戏资源时收到“加载”消息,并在完成后开始游戏。好的,谢谢,但当我使用.png文件实现阵列时,它们是否还没有加载?你能更具体地谈谈你的想法吗?如何安排?您知道150x150乘以700大约等于60MB内存使用量吗?根据其他mem使用情况和设备的不同,您可能无法同时将所有这些内容放入内存中。我的完整文件夹已将7,4 mb缩减为420张图片,使用250px x 250px谢谢您对我有用。我不知道预加载方法。预加载就是答案。虽然我在场景开始时填充数组,但第一次动画还是比较滞后。预加载解决这个问题。谢谢。我在预加载纹理图集时遇到fps下降,尽管我在仪器中验证了这项工作是在工作线程上完成的。我还尝试将其包装在全局调度队列的异步块中,但这没有帮助。你知道这是什么原因吗?