我正在开发一款游戏,在主菜单中我想制作动画。我认为使用图集来合并这个动画的所有图像会更好,但我发现从纹理图集制作图像并不像制作SKTextures那么容易。我的游戏的很大一部分已经开发出来,所以我不想在控制器中进行大的改动,以便能够在主菜单中加入SKTexture
我只是想知道,有没有办法从SKTexture创建获取UIImage?或者是否有一种方式使[UIImage imageNamed:[NSString stringWithFormat:@"imageInsideAtlas"]]
有效?
答案 0 :(得分:1)
您可以在屏幕外显示纹理,并基本上为UIImage创建快照:
-(UIImage*)snapshot
{
// Captures SpriteKit content!
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshotImage;
}
答案 1 :(得分:0)
纹理图集是为了与Sprite Kit一起使用而构建的,因此它为您提供了SKTextures而不是UIImages。我担心,没有简单的方法可以从纹理图集中获取UIImages。
考虑从纹理图集加载SKTextures并使用它们为SKSpriteNode设置动画。