Question

I have a scene with an SKEmitterNode which works fine when directly added to the scene.

However, I want to add a SKEffectNode on the scene to blur the emitter particles.

This is how it looks.

@implementation MyScene

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */

        self.backgroundColor = [SKColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

        SKEffectNode *blurNode = [[SKEffectNode alloc] init];

        CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
        [blurFilter setValue:@10.0 forKey:kCIInputRadiusKey];
        blurNode.filter = blurFilter;
        blurNode.shouldEnableEffects = YES;

        NSString *bokehPath = [[NSBundle mainBundle] pathForResource:@"Bokeh" ofType:@"sks"];
        SKEmitterNode *bokeh = [NSKeyedUnarchiver unarchiveObjectWithFile:bokehPath];
        [blurNode addChild:bokeh];

        [self addChild:blurNode];
    }
    return self;
}

This results in a blank screen.

Since a SKScene is a subclass of SKEffectNode as well, I tried adding a CIFilter to the scene directly as well.

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */

        self.backgroundColor = [SKColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

        CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
        [blurFilter setValue:@10.0 forKey:kCIInputRadiusKey];

        NSString *bokehPath = [[NSBundle mainBundle] pathForResource:@"Bokeh" ofType:@"sks"];
        SKEmitterNode *bokeh = [NSKeyedUnarchiver unarchiveObjectWithFile:bokehPath];
        [self addChild:bokeh];

        self.filter = blurFilter;
    }

    return self;
}

Same result.

Was it helpful?

Solution

It's possible to achieve this effect if you indeed apply the filter to the scene directly. Add the following to your second code:

self.shouldEnableEffects = YES;

If you still see a blank screen, try using bright-coloured particles on a black background instead of your white one for this effect. But expect the framerate to drop considerably. You might be better off using a blurred texture for the particles themselves in the Particle Editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top