如何在精灵工具包中获取截图?

时间:2014-07-28 19:43:33

标签: ios objective-c sprite-kit screenshot

当我试图抓住spritekit中的屏幕截图时。我已经尝试了所有可以在网上找到的方法。他们没有工作。

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *gameOverScreenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

只是没有工作

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

无法识别自我和规模。

1 个答案:

答案 0 :(得分:3)

我不确定-drawViewHierarchyInRect:afterScreenUpdates:是否应该与SKView一起工作(我假设如此),但第二个例子不编译的原因是(1)你试图调用它和{ {1}上的{1}}(可能是UIViewController)而不是bounds和(2)您没有定义self的值。只需改变这两行:

self.view

此外,scale的第二个参数 - “opaque” - 除非您的视图是透明的,否则不应为NO,并且只有在某些可能不包含此内容的情况下才需要将“afterScreenUpdates”设置为YES一。通过更改它们可能会看到更好的性能。