Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpriteKit support #30

Open
ralfebert opened this issue Jan 18, 2018 · 5 comments
Open

SpriteKit support #30

ralfebert opened this issue Jan 18, 2018 · 5 comments

Comments

@ralfebert
Copy link

Snap will render an empty, transparent image for SKViews. As a workaround, checking and handling for Spritekit in UIView+Render seems to do the trick:

if let skview = self as? SKView {
    return UIImage(cgImage: skview.texture(from: skview.scene!)!.cgImage())
}
@skyweb07
Copy link
Owner

Ohh that's awesome, I really haven't tried working with SpriteKit, but it could be superb if you could open a PR with a fix, thanks!!!

@ralfebert
Copy link
Author

This needs a bit more work, it doesn't seem to capture Retina images. Also I added some code to capture SpriteKit views in the hierarchy via a workaround: it adds an image view with the captured image via the SpriteKit API before capturing the whole view:
ralfebert@b0b0203
It works fine for me, but I think this code needs a bit more testing/polishing.

@ralfebert
Copy link
Author

I found that all these cases can be handled easily by using the UIView snapshotView method. It returns a "image" view which can be drawn using drawHierarchy and always shows what a user would see. I am currently using this in UIView+render and it does seem to do the trick.

@ralfebert
Copy link
Author

Ahh, big relevation: drawHierarchy works fine! But currently, Snap renders the layer of the view on top of the view in UIView+Render:

    drawHierarchy(in: bounds, afterScreenUpdates: true)
    layer.render(in: context)   // <---

And this breaks capturing views from GLKit, SceneKit and SpriteKit.
What is this about / for what is rendering the layer needed / is this not included in drawHierarchy?

@ralfebert
Copy link
Author

Ah, drawHierarchy only works when a UIWindow is present, thats why layer.render is there as well.

But I think rendering twice, once using drawHierarchy, then on top of it as a layer isn't correct (I also saw some render glitches due to that).

I am currently working on a pull request to properly capture SpriteKit and SceneKit.

I think always using layer.render() is the way to go, because it also works headless without a host application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants