I am following Apple's SpriteKit documentation, now I am trying to use SKEffectNode, but my problem is the effect will not be applied! Here is my code :

SKEffectNode *lightingNode = [[SKEffectNode alloc] init];
SKTexture *texture = [SKTexture textureWithImage:[UIImage imageNamed:@"Spaceship"]];
SKSpriteNode *light = [SKSpriteNode spriteNodeWithTexture:texture];
self.filter = [self blurFilter];
lightingNode.position = self.view.center;
lightingNode.blendMode = SKBlendModeAdd;
[lightingNode addChild: light];
[self addChild:lightingNode];

//applying blur 

- (CIFilter *)blurFilter
{
    CIFilter *filter = [CIFilter filterWithName:@"CIBoxBlur"]; // 3
    [filter setDefaults];
    [filter setValue:[NSNumber numberWithFloat:20] forKey:@"inputRadius"];
    return filter;
}

When you run the app it just show spaceship without any blur effect.

有帮助吗?

解决方案

It looks like @"CIBoxBlur" filter doesn't exist anymore, at least in iOS 7.0. You can use @"CIGaussianBlur". You can see full list of the filters by running:

    NSArray* filters = [CIFilter filterNamesInCategories:nil];
    for (NSString* filterName in filters)
    {
        NSLog(@"Filter: %@", filterName);
    }

其他提示

I don't see anywhere that you're setting the filter property of the effect node you've created, nor where you're setting its shouldEnableEffects property to YES.

As implied by the aforelinked documentation, both of those properties need a meaningful value if your effect node is to apply a filter.

I used your code with the following changes and all tested great!

//switch this  
lightingNode.position
//to this
light.position 
//add this 
lightingNode.shouldEnableEffects = YES;
//change 
CIBoxBlur
//to
CIGaussianBlur
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top