문제

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