ios Sprite Kit screengrab? [英] ios Sprite Kit screengrab?

查看:86
本文介绍了ios Sprite Kit screengrab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图获取一个包含SKScene的视图的屏幕抓取。我使用的技术是:

I am trying to get a screen grab of a view that has a SKScene in it. The technique I am using is:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这适用于普通的UIViews,但无论出于什么原因,它都忽略了SKScene中的所有精灵。

This works great with normal UIViews, but for whatever reason it is ignoring all the sprites in the SKScene.

我不确定这是否是一个错误,或者Sprite Kit的渲染是否与UIGraphics分开。

I'm not sure if this is a bug, or if Sprite Kit's rendering is separate from UIGraphics.

问题:当UIViews的工作方式似乎无法与Sprite Kit一起使用时,或者有人使用Sprite Kit使用UIGraphics上下文时,如何获得SKScene的屏幕抓取?

Question: How do I get a screen grab of an SKScene when the way that worked for UIViews seems to not work with Sprite Kit, or has anyone had success using UIGraphics context with Sprite Kit?

推荐答案

你几乎拥有它,但问题如上面的评论所述。如果你想捕获 SKScene 内容,请尝试这样的事情:

You almost have it, but the problem is as explained in the comment above. If you want to capture SKScene contents, try something like this instead:

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

解决方案是基本上使用新方法 drawViewHierarchyInRect:afterScreenUpdates 相反,这是我们现在最好的;请注意,它不是很快,所以实时做这件事并不漂亮。

The solution is to basically use the new method drawViewHierarchyInRect:afterScreenUpdates instead, which is the best we have for now; note, it's not exactly speedy, so doing this in realtime will not be pretty.

这篇关于ios Sprite Kit screengrab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆