Ios 与SKEffectNode有问题
我正在关注苹果的SpriteKit文档,现在我正在尝试使用SKEffectNode,但我的问题是效果不会被应用!这是我的密码:Ios 与SKEffectNode有问题,ios,iphone,objective-c,sprite-kit,skeffectnode,Ios,Iphone,Objective C,Sprite Kit,Skeffectnode,我正在关注苹果的SpriteKit文档,现在我正在尝试使用SKEffectNode,但我的问题是效果不会被应用!这是我的密码: SKEffectNode *lightingNode = [[SKEffectNode alloc] init]; SKTexture *texture = [SKTexture textureWithImage:[UIImage imageNamed:@"Spaceship"]]; SKSpriteNode *light = [SKSpriteNode spriteN
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;
}
当你运行该应用程序时,它只显示spaceship,没有任何模糊效果 我看不到您在任何地方设置所创建效果节点的属性,也看不到您在哪里将其属性设置为“是”
正如前面链接的文档所暗示的,如果效果节点要应用过滤器,那么这两个属性都需要一个有意义的值。至少在iOS 7.0中,@CIBoxBlur filter似乎已经不存在了。您可以使用@CIGaussianBlur。您可以通过运行以下命令查看过滤器的完整列表:
NSArray* filters = [CIFilter filterNamesInCategories:nil];
for (NSString* filterName in filters)
{
NSLog(@"Filter: %@", filterName);
}
我用你的代码做了以下修改,所有测试都很棒
//switch this
lightingNode.position
//to this
light.position
//add this
lightingNode.shouldEnableEffects = YES;
//change
CIBoxBlur
//to
CIGaussianBlur
谢谢,我修改了lightingNode.filter=[自模糊过滤器];添加shouldEnableEffects,但仍然没有发生任何事情!嗯,我也没有看到任何在lightingNode的坐标空间内定位灯光的东西。可能就是这样。