首次播放动画时游戏冻结



我正在使用精灵套件制作游戏,当我第一次播放动画时,游戏停止了几帧,这很烦人。我该如何解决这个问题?
当我加载我的SKSpriteNode时,我加载了这样的动画纹理:

    self.frames = [[NSMutableArray alloc] init];
    SKTextureAtlas *shieldAtlas = [SKTextureAtlas atlasNamed:@"shield"];
    for (int i = 0; i < [shieldAtlas.textureNames count]; i++) {
        NSString *tempName = [NSString stringWithFormat:@"shield%.3d", i];
        SKTexture *tempTexture = [shieldAtlas textureNamed:tempName];
        if (tempTexture) {
            [self.frames addObject:tempTexture];
        }}

当需要播放它时,我会像往常一样采取行动,它就在这里冻结。第一次之后,一切正常,没有任何减速。

[self.shield runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:self.frames timePerFrame:0.1 resize:YES restore:NO]] withKey:@"shield"];
在将

纹理添加到数组后立即添加此代码块对我有帮助。我猜它们是延迟加载的,仅在访问时加载到内存中。

[tempTexture preloadWithCompletionHandler:^{
    // duh duh
}];

最新更新