5

I am trying to apply CIGaussianBlur effect on Game Pause screen. Here is my code:

effectsNode = SKEffectNode();
let filter = CIFilter(name: "CIGaussianBlur");
let blurAmount = 10.0;
filter.setValue(blurAmount, forKey: kCIInputRadiusKey);

effectsNode.filter = filter;
effectsNode.blendMode = .Alpha;

This code is working perfectly but it takes too much processing power and reduces the FPS by a great deal! I just want a static blurred image of the background when the game is paused.

Is there a workaround to this problem?

Adnan Zahid
  • 573
  • 1
  • 10
  • 38
  • 1
    try the shouldRasterize property (or similar, it's got "rasterize" in its name) – CodeSmile Feb 17 '15 at 19:48
  • @LearnCocos2D I wish I saw this earlier, anyway I followed the post the answer mentions and got it working after a bit of tweaking :) I took a screenshot and applied the blur effect once, what alternative costs the least memory? Rasterization or taking a screenshot and blurring it? – Adnan Zahid Feb 17 '15 at 20:31

1 Answers1

1

Are you applying the effect on each frame? You should apply it only once and then save the result, and show that result during pause. You can see an example of this in this post

Community
  • 1
  • 1
Cihan Tek
  • 5,349
  • 3
  • 22
  • 29
  • 2
    The linked answer, though it is the accepted answer to that question, is not the most efficient solution — there's no need to roundtrip image data out of SpriteKit (where it's in GPU memory) to UIKit (in CPU memory) to apply a filter and drop it back into Spritekit. [Another answer](http://stackoverflow.com/a/22494746/957768) to that same question illustrates using `SKEffectNode` with the `shouldRasterize` option, so that the blur filter is applied only once, instead of on every draw. (Indeed, fullscreen blur at 60fps is too much for some hardware.) – rickster Feb 17 '15 at 21:30