我的节点上有几帧动画,我第一次播放动画时它滞后,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/