ios - 如何在 Sprite Kit 中预加载纹理?

标签 ios textures sprite-kit

我的节点上有几帧动画,我第一次播放动画时它滞后,fps 下降。每次下一次都很好,花花公子。

如何预加载纹理以使其运行顺畅?

当我加载游戏时,我有这个方法运行:

- (void)load
{
    self.animationFrames = @[[SKTexture textureWithImageNamed:@"exp1"], [SKTexture textureWithImageNamed:@"exp2"],
                             [SKTexture textureWithImageNamed:@"exp3"], [SKTexture textureWithImageNamed:@"exp4"], [SKTexture textureWithImageNamed:@"exp5"], [SKTexture textureWithImageNamed:@"exp6"], [SKTexture textureWithImageNamed:@"exp7"], [SKTexture textureWithImageNamed:@"exp8"], [SKTexture textureWithImageNamed:@"exp9"]];
}

还有这个播放动画的方法:

-(void)playExplosionAnimation
{
    self.size = CGSizeMake(250, 250);
    SKAction *animation = [SKAction animateWithTextures:self.animationFrames timePerFrame:0.1];

    [self runAction:animation completion:^{
        self.hidden = YES;
    }];
}

最佳答案

你应该创建一个 texture atlas并使用 SKTextureAtlas方法:

– preloadWithCompletionHandler:
+ preloadTextureAtlases:withCompletionHandler:

这是文档对此的描述:

Sprite Kit creates a background task that loads the texture data from the atlas. Then, Sprite Kit returns control to your game. After the texture atlas is loaded, your completion handler is called.

If you need to preload multiple texture atlases at once, use the preloadTextureAtlases:withCompletionHandler: method instead.

关于ios - 如何在 Sprite Kit 中预加载纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105911/

相关文章:

ios - 对象属性的 Getter 需要返回 UnsafeMutablePointer<T>?

iPhone:根据 Storyboard正确隐藏 UITableViewCell 中的附件按钮

ios - 撤消/恢复对 PFObject 的本地更改

ios - 读取重定向的 NSURLDataTask 的数据/响应/正文

c++ - irrlicht 模型加载/动画

javascript - 你能在 three.js 中提供一个作为纹理加载的图像作为另一个纹理 mipmap 吗?

javascript - 如何使用 gl_Position 以编程方式平移纹理

ios - 请在 Apple SpriteKit 示例代码中解释 uint32_t 和 0x1 << 0

ios - 如何正确初始化类

swift - 在 Spritekit 中改变场景,检测按钮上的触摸