.png 动画在 spritekit 中表现缓慢

.png animation slow performance in spritekit

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

它工作正常,但每次动画开始时,整个游戏都会冻结大约 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
    }
}