1

There are a lot of questions about how to do blur in SpriteKit, most of which seem to use a CIGaussianBlur filter. I have done this, but it seems to be slow for blurring large images, and there are other issues such as the blurring at the edges.

The UIBlurEffect seems to be the perfect tool for UIKit views, and my understanding is that it is optimised and performant and it seems that it would the best effect if it worked in SpriteKit.

What I am wondering is if somehow it is possible to leverage the UIKit blur while in SpriteKit. For example, take a UIImage, fake a UIKit UIImageView somehow, blur it, grab the blurred image and then use it as a texture in an SKSpriteNode.

I am not looking to blur the whole scene, just one node in it, and I don't want to use any third party libraries.

rghome
  • 8,529
  • 8
  • 43
  • 62
  • As far as I know, `UIKit` elements won't work inside `SpriteKit` elements. If you need a blurred image to be shown, the only option I can suggest from my knowledge is to add it to the viewcontroller directly, which realistically is not a practical solution in most cases. – Harikrishnan Dec 02 '15 at 11:28
  • I agree, but I am wondering if I can fake a UIKit context somehow, use that and then grab the result and pull it into SpriteKit. – rghome Dec 02 '15 at 12:28
  • A dirty hack is possible. I would recommend not to try it since `CIGaussianBlur` might be faster. The visualeffectview doesn't actually blur an image, so you can't use it to blur an image either inside or outside UIKit. It just add some layers and make the appearance of the blurred image. If you need the same effect you can create a view using visualeffectview and then draw it using CGGraphics, which of course is a real real dirty an unprofessional hack. :-) – Harikrishnan Dec 02 '15 at 12:34
  • If CIGaussianBlue is too slow for you, you could just prerender a blur glass pane, save it as an image, and lay this glass pane over your image you need blurred – Knight0fDragon Dec 02 '15 at 19:04
  • In fact, I am using the pre-rendering approach at the moment, fading it into the main image. There is a slight delay while the rendering takes place, which I have mitigated by doing it in background slightly in advance of when I need it and then delaying the start of the fade-in action if it is not ready.However, if someone posts a solution to do a real-time blur in SpriteKit using UIKit blur, then I will accept it. – rghome Dec 03 '15 at 09:26

0 Answers0